Skip to content

Commit 57922ba

Browse files
anci3ntr0ckanci3ntr0cksydney-runkle
authored
Add a check on the existence of __qualname__ (pydantic#8642)
Co-authored-by: anci3ntr0ck <[email protected]> Co-authored-by: Sydney Runkle <[email protected]>
1 parent 3810c7b commit 57922ba

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Diff for: pydantic/_internal/_model_construction.py

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def inspect_namespace( # noqa C901
334334
elif (
335335
isinstance(value, type)
336336
and value.__module__ == namespace['__module__']
337+
and '__qualname__' in namespace
337338
and value.__qualname__.startswith(namespace['__qualname__'])
338339
):
339340
# `value` is a nested type defined in this namespace; don't error

Diff for: tests/test_create_model.py

+9
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,12 @@ class Y:
601601
)
602602
Z = create_model('Z', y=(module.Y, ...))
603603
assert Z(y={'x': {}}).y is not None
604+
605+
606+
def test_type_field_in_the_same_module():
607+
class A:
608+
pass
609+
610+
B = create_model('B', a_cls=(type, A))
611+
b = B()
612+
assert b.a_cls == A

0 commit comments

Comments
 (0)