Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warning with usage of ast.Str #8837

Merged
merged 1 commit into from Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions pydantic/_internal/_docs_extraction.py
Expand Up @@ -25,8 +25,12 @@ def visit_AnnAssign(self, node: ast.AnnAssign) -> Any:
self.target = node.target.id

def visit_Expr(self, node: ast.Expr) -> Any:
if isinstance(node.value, ast.Str) and self.previous_node_type is ast.AnnAssign:
docstring = inspect.cleandoc(node.value.s)
if (
isinstance(node.value, ast.Constant)
and isinstance(node.value.value, str)
and self.previous_node_type is ast.AnnAssign
):
docstring = inspect.cleandoc(node.value.value)
if self.target:
self.attrs[self.target] = docstring
self.target = None
Expand Down