Skip to content

Commit 46d6baf

Browse files
Fixed stubs generation for non-read-only properties with implicitly convertible types
1 parent cad112f commit 46d6baf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

custom_stubgen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def write_module(self, module: Module, printer: Printer, to: Path, sub_dir: Opti
3030
for prop in cls.properties:
3131
if prop.setter is not None:
3232
self._patch_function(prop.setter)
33+
for field in cls.fields:
34+
if field.attribute.annotation is not None and field.attribute.annotation.name in self.alternative_types:
35+
converted_types = [ResolvedType(e) for e in self.alternative_types[field.attribute.annotation.name]]
36+
field.attribute.annotation = ResolvedType(
37+
QualifiedName.from_str("typing.Union"), [field.attribute.annotation] + converted_types)
3338
super().write_module(module, printer, to, sub_dir=sub_dir)
3439

3540

0 commit comments

Comments
 (0)