@@ -27,31 +27,6 @@ def transform_annotation(annotation: str, *, union: str = "Union") -> str:
27
27
return unparsed
28
28
29
29
30
- def write_anno_expr (
31
- tree : ast .Expression | ast .Name | ast .Subscript | ast .Attribute | ast .expr ,
32
- ):
33
- expr = tree .body if isinstance (tree , ast .Expression ) else tree
34
- if isinstance (expr , ast .Name ):
35
- return expr .id
36
- if isinstance (expr , ast .Subscript ):
37
- val = expr .slice .value # type: ignore[attr-defined]
38
- if isinstance (val , ast .Tuple ):
39
- subscript = ", " .join (write_anno_expr (c ) for c in val .elts )
40
- else :
41
- subscript = write_anno_expr (val )
42
- return f"{ write_anno_expr (expr .value )} [{ subscript } ]"
43
- if isinstance (expr , ast .List ):
44
- children = ", " .join (write_anno_expr (c ) for c in expr .elts )
45
- return f"[{ children } ]"
46
- if isinstance (expr , ast .Constant ):
47
- return str (expr .value )
48
-
49
- if isinstance (expr , ast .Attribute ):
50
- return expr .attr
51
-
52
- raise ValueError (ast .dump (tree ))
53
-
54
-
55
30
class TransformUnion (ast .NodeTransformer ):
56
31
def visit_BinOp (self , node : ast .BinOp ):
57
32
if not isinstance (node .op , ast .BitOr ):
@@ -82,13 +57,6 @@ def visit_Name(self, node: ast.Name):
82
57
return new
83
58
84
59
85
- def contained_generic (string : str ) -> tuple [bool , int ]:
86
- opens = string .count ("[" )
87
- closes = string .count ("]" )
88
- hanging = opens - closes
89
- return hanging == 0 , hanging
90
-
91
-
92
60
_GENERICS = {
93
61
"dict" : "typing.Dict" ,
94
62
"list" : "typing.List" ,
0 commit comments