-
-
Notifications
You must be signed in to change notification settings - Fork 117
Add SupportsLessThan to typing and typing_extensions #9
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
Comments
Sounds like a good idea. In fact, adding protocols for other dunder protocols makes sense, too. See for example the dunder protocols in builtins. |
Adding it to typing(_extensions) is relatively painful though because it ties us to Python's release cycle. An alternative could be to release our |
Oops, I was misreading this. I was talking about |
The Example given above was this Item = TypeVar("Item")
def try_sort(iterable: Iterable[Item]) -> Iterable[Item]:
# Pulled from pandas.core.common since
# it was deprecated and removed in 1.1
listed = list(iterable)
try:
return sorted(listed)
except TypeError:
return listed
So, I changed it to str and it worked 😮 def try_sort(iterable: Iterable[str]) -> Iterable[str]:
# Pulled from pandas.core.common since
# it was deprecated and removed in 1.1
listed = list(iterable)
try:
return sorted(listed)
except TypeError:
return listed I am trying to figure out what was the general solution to this issue? |
Note that typing_extensions is not tied to the CPython release cycle. |
The general solution if we add this to
If this isn't added to But now that I'm looking closely at your code, some more comments:
It sounds like no one is opposed, but no one feels strongly either? In that case, maybe we hold off and see if people complain, rather than presumptively making a decision based on mypy_primer. |
@hauntsaninja, I am facing the same problem with
The lines involved are the ones below |
@guilhermeleobas Hmm, your false positive is a little tricky. The problem is that there isn't a good way to type the return type of Some possibilities:
|
Thanks @hauntsaninja, I will give it a try. |
I ended up here after upgrading my code from mypy 0.770 to 0.810, and this was the biggest issue I ran into. I have a handful of sort key functions that I had previously annotated as returning Hashable. I understand why Hashable wasn't right, I'm glad that's an error now, but I was a little sad there wasn't an easy low-level type to use in the typing module that I could correctly replace it with. For me probably the best value I get out of type checking, after catching obvious bugs, is the way it helps document my code. Even though my sort key functions return higher-level types and I could annotate them as such, I like the low-level type annotation as a signal to say "I only promise this return value is comparable against other return values; don't try to do anything else with it." For that reason, I would appreciate an easy way to import "the return type of a sort key function." |
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
After a year of not working o deadlinks, there are some broken things that needs to be fixed: - ci: move to github actions from travis-ci - mypy: issue regarding totalordering - https://github.com/python/typing/issues/760 - tests: some tests are broken - adding: act to test github actions integration.
I also ran into this issue. |
Closing this as our current policy is to add only types that are in In addition, typeshed no longer has a |
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed Instead of defining the protocol conditionally (`if TYPE_CHECKING:`), we're just going to define it always.
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed This just removes SupportsLessThan altogether. I checked a few places where we sort by BundleFQID and got no warnings from PyCharm.
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed This just removes SupportsLessThan and the implicit ordering of BundleFQID altogether.
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed This just removes SupportsLessThan and the implicit ordering of BundleFQID altogether.
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed
Upstream issue (python/typing_extensions#9) was closed without fix. SupportLessThan was removed from _typeshed. I believe it was never marked stable so it was never safe to import from there anyways. https://github.com/python/typeshed/tree/main/stdlib/_typeshed
The latest version of mypy / typeshed uses a protocol for things passed to sorted / sort. As measured by mypy_primer, this was a fairly disruptive change. To correctly type some usage of sort / sorted, you need the protocol, and it's pretty hard for users to figure this out, eg: elastic/eland#283 (comment)
Adding the protocol to typing / typing_extensions would make this solution more discoverable and involve less end user protocol redefinition boilerplate when used.
The text was updated successfully, but these errors were encountered: