This results in a generated directory that looks like
Foo.py
Bar.py
A Foo.py that looks like
class Foo(BaseModel):
# ...
And a Bar.py that looks like
from . import Foo
class Bar(BaseModel):
foo: Optional[Foo] = None
I then package this module and publish it on a private repo. When I try to use it in another project, I get the following error
TypeError: typing.Optional requires a single type. Got <module 'Foo'> from '...'
I believe this error happens because the module and class have the same name. If i try again, but rename the module to Foo2.py, then the genereated Bar.py looks like
from . import Foo2
class Bar(BaseModel):
foo: Optional[Foo2.Foo] = None
And there's no error
Expected behavior
The Foo class should be used for typing instead of the Foo module.
Describe the bug I have a directory of json schemas that cannot be modified. Inside this directory, there are several files with the following layout:
This results in a generated directory that looks like
A Foo.py that looks like
And a Bar.py that looks like
I then package this module and publish it on a private repo. When I try to use it in another project, I get the following error
I believe this error happens because the module and class have the same name. If i try again, but rename the module to
Foo2.py
, then the genereatedBar.py
looks likeAnd there's no error
Expected behavior The
Foo
class should be used for typing instead of theFoo
module.Version: