Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CharField missing __init__ declaration #136

Open
bschnurr opened this issue Sep 28, 2022 · 6 comments
Open

CharField missing __init__ declaration #136

bschnurr opened this issue Sep 28, 2022 · 6 comments

Comments

@bschnurr
Copy link

microsoft/pylance-release#3401

@sbdchd
Copy link
Owner

sbdchd commented Sep 29, 2022

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
Copy link
Author

bschnurr commented Oct 6, 2022

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

@bschnurr
Copy link
Author

bschnurr commented Oct 6, 2022

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

@chdsbd
Copy link
Collaborator

chdsbd commented Oct 6, 2022

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

@chdsbd
Copy link
Collaborator

chdsbd commented Oct 6, 2022

@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
Copy link
Author

Pylance/pyright have been updated to look at __new__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants