File tree Expand file tree Collapse file tree 5 files changed +24
-16
lines changed
Expand file tree Collapse file tree 5 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 11from collections import OrderedDict
22from dataclasses import dataclass
3+ from typing import Optional
34
45
56@dataclass (
67 order = True ,
78)
89class ClassFound :
9- # def __eq__(self, other):
10- # if not isinstance(other, ClassFound):
11- # return False
12- # if self.fields != other.fields:
13- # return False
14- # return True
1510 name : str
1611 filePath : str
1712 raw_fields : OrderedDict
1813 fields : OrderedDict
1914 doc : str
15+ class_raw : Optional [type ] = None
16+
Original file line number Diff line number Diff line change @@ -28,27 +28,30 @@ def func_with_nested_arg_class(a: ParentClass) -> ParentClass:
2828
2929 child_class = ClassFound (
3030 name = 'ChildClass' ,
31- fields = OrderedDict ( {
31+ fields = {
3232 'return' : None ,
3333 'carg1' : str ,
34- }) ,
34+ },
3535 doc = '' ,
3636 filePath = '' ,
3737 raw_fields = OrderedDict (),
38+ class_raw = ChildClass ,
3839 )
3940 parent_class = ClassFound (
4041 name = "ParentClass" ,
41- fields = OrderedDict ( {
42+ fields = {
4243 'return' : None ,
4344 'parg1' : str ,
4445 'parg2' : child_class ,
45- }) ,
46+ },
4647 doc = '' ,
4748 filePath = '' ,
4849 raw_fields = OrderedDict (),
50+ class_raw = ParentClass
4951 )
5052 parent_cleaned = traverse (parent_class , cleanup )
5153 child_cleaned = traverse (child_class , cleanup )
54+ import pdb ;pdb .set_trace ()
5255 assert (parent_cleaned == cleanedup )
5356 assert (classes_list .__len__ () == 2 )
5457 assert (functions_list .__len__ () == 1 )
Original file line number Diff line number Diff line change 11from py_codegen .type_extractor .ClassFound import ClassFound
22
33
4- def test_utils_cleanup_nested_classfound ():
5- parent_class = ClassFound (
6- name = 'somewhere' ,
7- filePath = 'parent' ,
8-
9- )
4+ # def test_utils_cleanup_nested_classfound():
5+ # parent_class = ClassFound(
6+ # name='somewhere',
7+ # filePath='parent',
8+ #
9+ # )
Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ def cleanup(node: Union[ClassFound, FunctionFound]):
7575 if isinstance (node , ClassFound ):
7676 new_node = deepcopy (node )
7777 new_node .raw_fields = OrderedDict ()
78+
79+ # python 3.7.2 adds 'return': None to no-return classes.
80+ new_node .fields .update ({
81+ 'return' : new_node .fields .get ('return' )
82+ })
7883 new_node .filePath = ''
7984 new_node .doc = ''
8085 return new_node
Original file line number Diff line number Diff line change 1010from .FunctionFound import FunctionFound
1111from .TypeOR import TypeOR
1212
13+
1314def is_builtin (something ):
1415 return inspect .getmodule (something ) is builtins
1516
17+
1618class TypeExtractor :
1719 functions : Dict [str , FunctionFound ]
1820 classes : Dict [str , ClassFound ]
@@ -87,6 +89,7 @@ def __to_class_found(self, _class):
8789 fields = self .__process_params (fields_to_process )
8890 class_found = ClassFound (
8991 name = _class .__name__ ,
92+ class_raw = _class ,
9093 filePath = filename ,
9194 raw_fields = argspec .annotations ,
9295 fields = fields ,
You can’t perform that action at this time.
0 commit comments