File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class ParentClassA :
2+ from_parent_a : int
3+
4+
5+ class ParentClassB :
6+ from_parent_b : str
7+
8+
9+ class ChildClass (ParentClassA , ParentClassB ):
10+ b : str
Original file line number Diff line number Diff line change 1+ from py_codegen .test_fixtures .classes_with_inheritance import ChildClass
2+
3+ from py_codegen .type_extractor .nodes .BaseNodeType import BaseOption
4+ from py_codegen .type_extractor .nodes .ClassFound import ClassFound
5+ from py_codegen .type_extractor .nodes .TypeOR import TypeOR
6+ from py_codegen .type_extractor .__tests__ .utils import traverse , cleanup
7+ from py_codegen .type_extractor .type_extractor import TypeExtractor
8+
9+
10+ def test_classes_with_inheritance ():
11+ type_collector = TypeExtractor ()
12+
13+ type_collector .add (None )(ChildClass )
14+
15+ print (type_collector )
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ def class_found_middleware(
3030 return duplicate
3131
3232 _data_class = dataclass (_class )
33+ base_classes = [
34+ type_extractor .rawtype_to_node (base_cls )
35+ for base_cls in list (_class .__bases__ )
36+ if base_cls is not object and base_cls is not tuple
37+ ]
3338 argspec = inspect .getfullargspec (_data_class )
3439 module = inspect .getmodule (_class )
3540 filename = module and module .__file__
@@ -38,6 +43,7 @@ def class_found_middleware(
3843 name = _class .__name__ ,
3944 class_raw = _class ,
4045 filePath = filename ,
46+ base_classes = base_classes ,
4147 raw_fields = argspec .annotations ,
4248 fields = fields ,
4349 doc = _class .__doc__ ,
Original file line number Diff line number Diff line change 44 Dict ,
55 Any ,
66 Callable ,
7- Set )
7+ Set , List )
88
99from py_codegen .type_extractor .nodes .BaseNodeType import BaseNodeType , NodeType , BaseOption
1010
@@ -16,6 +16,7 @@ class ClassFound(BaseNodeType): # type: ignore
1616 filePath : str = field (default = '' )
1717 raw_fields : Dict [str , Any ] = field (default_factory = dict )
1818 doc : str = field (default = '' )
19+ base_classes : List ['ClassFound' ] = field (default_factory = list )
1920 class_raw : Optional [type ] = None
2021 INTERNAL_fields_extra : Optional [Dict [str , Any ]] = None
2122 options : Set [BaseOption ] = field (default_factory = set )
You can’t perform that action at this time.
0 commit comments