|
28 | 28 |
|
29 | 29 | PACKAGE = (Path(__file__) / "../../zenoh").resolve() |
30 | 30 | __INIT__ = PACKAGE / "__init__.py" |
| 31 | +EXT = PACKAGE / "ext.py" |
31 | 32 |
|
32 | 33 |
|
33 | 34 | def _unstable(item): |
@@ -55,7 +56,7 @@ def visit_ClassDef(self, node: ast.ClassDef): |
55 | 56 |
|
56 | 57 | def visit_FunctionDef(self, node: ast.FunctionDef): |
57 | 58 | for decorator in node.decorator_list: |
58 | | - if isinstance(decorator, ast.Name) and decorator.id == "overload": |
| 59 | + if isinstance(decorator, ast.Name) and decorator.id == "overload" and node.name != "__new__": |
59 | 60 | if node.name in self.overloaded_by_class[self.current_cls]: |
60 | 61 | # there is no implementation in stub, so one has to be added |
61 | 62 | # for (de)serializer |
@@ -98,23 +99,26 @@ def visit_FunctionDef(self, node: ast.FunctionDef): |
98 | 99 |
|
99 | 100 |
|
100 | 101 | def main(): |
101 | | - # remove __init__.pyi |
102 | | - __INIT__.unlink() |
| 102 | + fnames = [__INIT__, EXT] |
| 103 | + for fname in fnames: |
| 104 | + # remove *.py |
| 105 | + fname.unlink() |
103 | 106 | # rename stubs |
104 | 107 | for entry in PACKAGE.glob("*.pyi"): |
105 | 108 | entry.rename(PACKAGE / f"{entry.stem}.py") |
106 | | - # read stub code |
107 | | - with open(__INIT__) as f: |
108 | | - stub: ast.Module = ast.parse(f.read()) |
109 | | - # replace _unstable |
110 | | - for i, stmt in enumerate(stub.body): |
111 | | - if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable": |
112 | | - stub.body[i] = ast.parse(inspect.getsource(_unstable)) |
113 | | - # remove overload |
114 | | - stub = RemoveOverload().visit(stub) |
115 | | - # write modified code |
116 | | - with open(__INIT__, "w") as f: |
117 | | - f.write(ast.unparse(stub)) |
| 109 | + for fname in fnames: |
| 110 | + # read stub code |
| 111 | + with open(fname) as f: |
| 112 | + stub: ast.Module = ast.parse(f.read()) |
| 113 | + # replace _unstable |
| 114 | + for i, stmt in enumerate(stub.body): |
| 115 | + if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable": |
| 116 | + stub.body[i] = ast.parse(inspect.getsource(_unstable)) |
| 117 | + # remove overload |
| 118 | + stub = RemoveOverload().visit(stub) |
| 119 | + # write modified code |
| 120 | + with open(fname, "w") as f: |
| 121 | + f.write(ast.unparse(stub)) |
118 | 122 |
|
119 | 123 |
|
120 | 124 | if __name__ == "__main__": |
|
0 commit comments