-
-
Notifications
You must be signed in to change notification settings - Fork 2k
networkx: consistent Unknown | None = None
#14027
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
networkx: consistent Unknown | None = None
#14027
Conversation
|
This is inconsistent with what we're doing elsewhere in typeshed. That said, I can see us using that now that we include defaults in stubs. But if we do it we should do it consistently in typeshed, enforced by flake8-pyi. |
Unknown | NoneUnknown | None = None
|
Not everywhere, but mostly Some stubs might also use it in select places specifically to pass That being said, my opinion here is similar to #13765 and I would prefer this form. Anyway, for now my motivation is mainly to reduce accidental changes of |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
That's what I meant.
That's not a valid reason to use
I agree, this form is more succinct and obviously equivalent. |
|
This change appears to have led to the following new error:
I'm not well-versed in the state of these stubs, as it does appear quite a few annotations are missing, but the above seems somewhat worse (i.e. always an error) than the prior state. |
It is "worse", because it is accurate. Your type checker is now warning you that by using this method, you are forgoing static type safety, because no one validated which type you should be able to pass in. From here, you have two approaches:
|


Replaced
: Incomplete | None = Nonewith=None.Being consistent there will help reducing possible changes from merging https://github.com/microsoft/python-type-stubs/tree/main/stubs/networkx
This is still interpreted as
Any | Noneby mypy. And now more correctly interpreted asUnknown | Noneby pyright.