Skip to content

Commit 49f0eaf

Browse files
committed
Wip - fix issues with python 3.7.2
1 parent e4c4a11 commit 49f0eaf

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
from collections import OrderedDict
22
from dataclasses import dataclass
3+
from typing import Optional
34

45

56
@dataclass(
67
order=True,
78
)
89
class 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+

py_codegen/type_extractor/__tests__/test_func_with_nested_arg_class.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from 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+
# )

py_codegen/type_extractor/__tests__/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

py_codegen/type_extractor/type_extractor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
from .FunctionFound import FunctionFound
1111
from .TypeOR import TypeOR
1212

13+
1314
def is_builtin(something):
1415
return inspect.getmodule(something) is builtins
1516

17+
1618
class 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,

0 commit comments

Comments
 (0)