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

Add a check on the existence of __qualname__ #8642

Merged
merged 2 commits into from Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pydantic/_internal/_model_construction.py
Expand Up @@ -334,6 +334,7 @@ def inspect_namespace( # noqa C901
elif (
isinstance(value, type)
and value.__module__ == namespace['__module__']
and '__qualname__' in namespace
and value.__qualname__.startswith(namespace['__qualname__'])
):
# `value` is a nested type defined in this namespace; don't error
Expand Down
7 changes: 7 additions & 0 deletions tests/test_create_model.py
Expand Up @@ -601,3 +601,10 @@ class Y:
)
Z = create_model('Z', y=(module.Y, ...))
assert Z(y={'x': {}}).y is not None


def test_type_field_in_the_same_module():
class A:
pass

create_model('B', a_cls=(type, A))
sydney-runkle marked this conversation as resolved.
Show resolved Hide resolved