sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
188 stars 62 forks source link

refactor classes to use __init__ #139

Open chdsbd opened 1 year ago

chdsbd commented 1 year ago

I believe we previously used new to support Pylance. Now Pylance doesn't support new so we need to use init.

Mypy works either way, but this allows us to get Pylance working properly with auto complete.

related: #136

sbdchd commented 1 year ago

oh pyright is angry in CI, maybe it needs an update?

bschnurr commented 1 year ago

any eta?

chdsbd commented 1 year ago

@bschnurr We can make this change, but it breaks foreign keys for Pylance. Mypy still works though: https://github.com/sbdchd/django-types/issues/136#issuecomment-1270744593

bschnurr commented 1 year ago

@chdsbd found an alternative fix..

just remove def __init__(self, *args: Any, **kwargs: Any) -> None: ... from class Field and keep all the __new__ func definitions https://github.com/sbdchd/django-types/blob/842bcd6f6efac091b5ebd0565203cc367aa54140/django-stubs/db/models/fields/__init__.pyi#L124

then the previous __new__ function signatures will be picked up

__new__ and __init__ signatures aren't matching.

pyright does have a check for this. reportInconsistentConstructor

now i see a proper signature image

bschnurr commented 1 year ago

this is a pylance bug. working on a fix