Closed nats closed 1 year ago
How to test:
main
, run poetry run task generate
and verify via git diff
there are no changes.poetry env path
to see where your venv is , in that directory edit lib/python3.10/site-packages/openapi_python_client/parser/properties/property.py
find the line enable_lazy_imports = False
and change it to True.poetry run task generate
and verify via git diff
that the generated lib/ now contains forward references.enable_lazy_imports
to False, switch to this branch refactor/eager-imports
, run poetry run task generate
and verify git diff
there are no changes.enable_lazy_imports
to True, run poetry run task generate
and verify via git diff
there are no changes.
This PR will enable removal of the
enable_lazy_imports
changes from ouropenapi-python-client
fork, by providing the required alterations to generated code inscripts/generate.py
.In v0.12.0 upstream
openapi-python-client
changed the generated code to use ForwardRef type annotations in various parts of the generated code. This was a problem for us because ourformatter
module needs to resolve those types at runtime as it walks the response object, so the solution we used at the time was to add a newenable_lazy_imports
class attribute toProperty
and use its value to determine whether to change the behaviour of theProperty
hierarchy back to normal ('eager') imports.While it would be possible to feed the relevant types to
typing.get_type_hints()
via itslocalns
parameter; since we do not know ahead of time which particular types are required we would have to import all types frommodels
, which is a pretty significant performance hit for CLI usage.By performing the relevant fixups in
generate.py
, we avoid that while bringing us a step closer to switching back to the upstreamopenapi-python-client
.