Let's use this issue to track special stub rules that found their way into typeshed stubs. Since mypy is currently the only system used for testing typeshed, it's natural for some mypy logic to become reflected in the typeshed stubs.
So far I have:
When something is declared as taking unicode (in the PY2 stubs) then it actually also takes str/bytes.
It's implicit. This whole thread is about things that are implicit. (And the int <-> long equivalence actually is useful, precisely so that you don't have to use Union[int, long])
When using mypy with --strict-optional, None is no longer valid when bool is expected. Currently mypy considers None always valid for any type by default, not just for bool. Typeshed should use Optional[...] consistently. I think that providing None when bool is expected should generally be an error (except maybe if that turns out to generate a lot of false positives).
Thanks for the clarification! I'll edit the posts above.
I think that providing None when bool is expected should generally be an error.
That's what pytype used to do. But our internal users were complaining about it, so we now allow None, too. It seems "safe" enough. At least, it's not clear what a false negative would look like. (Maybe a function without a return?)
+1
This should definitely be documented in a more prominent place, instead of in the depths of the typeshed issue tracker.
pytype does the same thing as mypy.
All of the examples mentioned here have now been standardized in PEP 484, and we should not be standardizing any other mypy peculiarities in typeshed, so I don't see a reason to keep this open.
Activity
matthiaskramm commented on Jul 7, 2016
smontanaro commented on Jul 7, 2016
Is int <-> long implicit, or does everywhere I have "int" need to be changed to "Union[int, long]"?
matthiaskramm commented on Jul 7, 2016
It's implicit. This whole thread is about things that are implicit. (And the int <-> long equivalence actually is useful, precisely so that you don't have to use Union[int, long])
matthiaskramm commented on Aug 22, 2016
JukkaL commented on Aug 22, 2016
matthiaskramm commented on Aug 22, 2016
Thanks for the clarification! I'll edit the posts above.
That's what pytype used to do. But our internal users were complaining about it, so we now allow None, too. It seems "safe" enough. At least, it's not clear what a false negative would look like. (Maybe a function without a return?)
JukkaL commented on Aug 23, 2016
Here are some potential cases where None is not valid when expecting a bool:
JelleZijlstra commented on Apr 23, 2017
Is it worth adding the unicode/str and int/long promotions for Python 2.7 to PEP 484? Does pytype behave differently from mypy?
gvanrossum commented on Apr 23, 2017
I like the idea of specifying promotions in PEP 484. We'd have to have consensus from PyCharm (@vlasovskikh) and pytype (@matthiaskramm).
matthiaskramm commented on Apr 23, 2017
+1
This should definitely be documented in a more prominent place, instead of in the depths of the typeshed issue tracker.
pytype does the same thing as mypy.
PEP 484: Add implicit promotions for Python 2.7
JelleZijlstra commented on Apr 24, 2017
python/peps#245
PEP 484: Add implicit promotions for Python 2.7 (#245)
vlasovskikh commented on Apr 26, 2017
+1. PyCharm already supports these promotions except long -> int.
JelleZijlstra commented on Apr 4, 2018
All of the examples mentioned here have now been standardized in PEP 484, and we should not be standardizing any other mypy peculiarities in typeshed, so I don't see a reason to keep this open.