prisma-client-py icon indicating copy to clipboard operation
prisma-client-py copied to clipboard

Optimise generated types

Open RobertCraigie opened this issue 4 years ago • 4 comments

In order to circumvent mypy not supporting recursive types we duplicate every would-be recursive type. While this works it leads to a massive number of types being generated which slows down mypy considerably.

This appears to be unavoidable but we can improve performance by only generating types that will actually be used (we currently generate every possible relational type) and potentially re-using types.

We should also add a note to the docs somewhere that mypy performance can be improved by decreasing the depth of generated recursive types.

RobertCraigie avatar Jan 12 '21 20:01 RobertCraigie

This is also relevant as generating many types also increases memory usage significantly when static type checking

RobertCraigie avatar Jan 13 '21 20:01 RobertCraigie

Maybe mypy now has the recursive type support you need? https://github.com/python/mypy/issues/731#issuecomment-922760064

tday avatar Feb 18 '22 14:02 tday

@tday Unfortunately not, on mypy version 0.931 recursive TypedDicts are not supported.

Trying to type check will raise errors like these:

src/prisma/types.py:2759: error: Cannot resolve name "TypesScalarWhereWithAggregatesInput" (possible cyclic definition)  [misc]
        NOT: List['TypesScalarWhereWithAggregatesInput']

RobertCraigie avatar Feb 18 '22 16:02 RobertCraigie