-
-
Notifications
You must be signed in to change notification settings - Fork 493
Fill remaining missing hints with Any & disallow partial hints #1206
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
Fill remaining missing hints with Any & disallow partial hints #1206
Conversation
@intgr can you please solve merge conflicts? And I can then start reviewing it :) |
62ba65d
to
7324e63
Compare
# non-Model instances | ||
@overload | ||
def __get__(self: _T, instance, owner) -> _T: ... | ||
def __get__(self: _T, instance: Any, owner: Any) -> _T: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure what these owner
fields are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's type[M] | None = None
(if not in pyi)
Where
M = TypeVar("M", bound=Model)
And I think it's not none when instance is not none.
Making this an @overload
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in this specific overload both any's should be : None
I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flaeppe You're probably right but I'm wary of touching these since I don't totally understand what is happening here. Are you up for opening a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be fine keeping it as Any
since what's exposed as an API is _T
. The instance
and owner
types would only be relevant for the implementation body, but this is in stubs so we won't be affected here.
The only time they'd come in to play and have an impact would be while/if subclassing Field
and overriding it's descriptor methods. If we keep Any
, we'll allow a child class to declare them as whatever type they deem fit, while doing e.g. type[M] | None
we'll restrain it.
Though, in general I don't see any obvious use cases for overriding the descriptor for Field
, but I might be wrong here. The normal Django use case would be to implement a separate field descriptor class (https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.Field.descriptor_class) to decide what goes in and out of a model field
The idea here was to fill in all missing hints so that we could increase the strictness in I'm not making anything worse because I suppose I could do manual tweaks here and there, but it's increasing the scope of a change that's already enormous. Is that what we want? |
Ok! |
I'm okay with this, but after merging, can you open an issue or PR for |
e7662d9
to
faf8ff2
Compare
is it ready to be reviewed? or should we merge tests first? |
It contains all changes from the other PR also. But other than that it should be ready. |
I've merged test changes, there are conflicts now 👀 |
faf8ff2
to
81d05ee
Compare
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again! Maybe someone else will have some extra input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as a step towards stricter Mypy config.
This one just adds
Any
to all the remaining missing hints (most of those files are unhinted anyway) and disallows partial hints in mypy.ini