Skip to content

Add SupportsRichComparison type to _typeshed #6583

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

Merged
merged 3 commits into from
Dec 14, 2021

Conversation

AlexWaygood
Copy link
Member

Fixes #6575

Cc: @JukkaL

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
- pandas/core/indexes/base.py:3857: error: Argument 1 has incompatible type "Union[ExtensionArray, ndarray[Any, Any]]"; expected "Union[_SupportsLE, _SupportsGE, _SupportsGT, _SupportsLT]"  [arg-type]
+ pandas/core/indexes/base.py:3857: error: Argument 1 has incompatible type "Union[ExtensionArray, ndarray[Any, Any]]"; expected "Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]"  [arg-type]
- pandas/core/indexes/base.py:3857: error: Argument 2 has incompatible type "Union[ExtensionArray, ndarray[Any, Any]]"; expected "Union[_SupportsLE, _SupportsGE, _SupportsGT, _SupportsLT]"  [arg-type]
+ pandas/core/indexes/base.py:3857: error: Argument 2 has incompatible type "Union[ExtensionArray, ndarray[Any, Any]]"; expected "Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]"  [arg-type]
- pandas/core/arrays/sparse/array.py:1552: error: Cannot call function of unknown type  [operator]
- pandas/io/formats/style.py:3502: error: Argument 2 to "ge" has incompatible type "Union[str, Any, float, Period, Timestamp, Timedelta, Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union[_SupportsLE, _SupportsGE, _SupportsGT, _SupportsLT]"  [arg-type]
+ pandas/io/formats/style.py:3502: error: Argument 2 to "ge" has incompatible type "Union[str, Any, float, Period, Timestamp, Timedelta, Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]"  [arg-type]
- pandas/io/formats/style.py:3507: error: Argument 2 to "le" has incompatible type "Union[str, Any, float, Period, Timestamp, Timedelta, Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union[_SupportsLE, _SupportsGE, _SupportsGT, _SupportsLT]"  [arg-type]
+ pandas/io/formats/style.py:3507: error: Argument 2 to "le" has incompatible type "Union[str, Any, float, Period, Timestamp, Timedelta, Sequence[Any], ndarray[Any, Any], NDFrame]"; expected "Union[SupportsDunderLE, SupportsDunderGE, SupportsDunderGT, SupportsDunderLT]"  [arg-type]

paasta (https://github.com/yelp/paasta)
- paasta_tools/metrics/metastatus_lib.py:650: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[_SlaveT], SupportsLessThan]"
+ paasta_tools/metrics/metastatus_lib.py:650: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[_SlaveT], Union[SupportsDunderLT, SupportsDunderGT]]"
- paasta_tools/metrics/metastatus_lib.py:650: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[Any], SupportsLessThan]"
+ paasta_tools/metrics/metastatus_lib.py:650: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[Any], Union[SupportsDunderLT, SupportsDunderGT]]"

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/watcher/local_sources_watcher_test.py:294:47: error: Returning Any from function declared to return "SupportsLessThan"  [no-any-return]
+ lib/tests/streamlit/watcher/local_sources_watcher_test.py:294:47: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]

Copy link
Contributor

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, these types seem to reflect the runtime behavior more precisely!

@JukkaL JukkaL merged commit 5670ca2 into python:master Dec 14, 2021
@AlexWaygood AlexWaygood deleted the rich-comparisons branch December 14, 2021 14:17
AlexWaygood added a commit to AlexWaygood/mypy that referenced this pull request Mar 15, 2022
`SupportsLessThan` was removed from `_typeshed` in python/typeshed#6583 and replaced with a new `SupportsRichComparison` type, which better reflects the types at runtime.

Fixes python#12355
97littleleaf11 pushed a commit to python/mypy that referenced this pull request Mar 15, 2022
`SupportsLessThan` was removed from `_typeshed` in 
python/typeshed#6583 and replaced with 
a new `SupportsRichComparison` type, which better reflects the 
types at runtime.

Fixes #12355
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

Successfully merging this pull request may close these issues.

max() works with greater-than or less-than
2 participants