sbdchd / django-types

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

CharField missing `__init__` declaration #136

Open bschnurr opened 1 year ago

bschnurr commented 1 year ago

https://github.com/microsoft/pylance-release/issues/3401

sbdchd commented 1 year ago

Pretty sure we use __new__ instead so that we can make both pyright and mypy happy:

https://cs.github.com/sbdchd/django-types/blob/8b5f4bcbfa3b3ee7663f2b502490f1d4a7021d98/django-stubs/db/models/fields/__init__.pyi?q=CharField#L687

might be worth revisiting if that's still necessary -- I can't remember which type checker preferred new to init

bschnurr commented 1 year ago

pyright seems to prefer init.. users not getting correct signatures anymore

bschnurr commented 1 year ago

I'll have to revert pylance back to the old stubs https://github.com/typeddjango/django-stubs for now

chdsbd commented 1 year ago

Yeah, we could probably change the types to use __init__ instead of __new__

chdsbd commented 1 year ago

@bschnurr I've refactored the type definitions to use __init__ in #139, but Pylance is having issues with understanding foreign keys. Mypy seems to work fine though and we do have better autocomplete.

reveal_type(comment.nullable_user_type)
mypy: Revealed type is "Union[tests.trout.models.User, None]"
Pylance: Type of "comment.nullable_user_type" is "_M@ForeignKey | None"
bschnurr commented 1 year ago

Pylance/pyright have been updated to look at __new__