Skip to content

Commit 949e742

Browse files
Merge pull request #19 from matthewwardrop/fix_nested_type_resolution
Fix nested type resolution in spec-classes.
2 parents 2d63efb + cc1ea33 commit 949e742

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spec_classes/spec_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def bootstrap(self, spec_cls: type):
261261
managed_attrs.extend(self.attrs)
262262

263263
# Generate namespace of annotations (in addition to local class context)
264-
annotation_namespace = {spec_cls.__name__: spec_cls}
264+
annotation_namespace = {spec_cls.__name__: spec_cls, **vars(spec_cls)}
265265
if hasattr(spec_cls, "ANNOTATION_TYPES"):
266266
spec_annotation_types = spec_cls.ANNOTATION_TYPES
267267
if hasattr(spec_annotation_types, "__call__"):

tests/test_spec_class.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,13 @@ class SubSpec(Spec):
879879
a = staticmethod(lambda x: x)
880880

881881
SubSpec() # Would fail if attempting to deepcopy `staticmethod`.
882+
883+
def test_nested_type_resolution(self):
884+
@spec_class
885+
class A:
886+
class B:
887+
pass
888+
889+
a: B
890+
891+
assert A.__spec_class__.attrs["a"].type is A.B

0 commit comments

Comments
 (0)