Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pandera (https://github.com/pandera-dev/pandera)
+ pandera/backends/xarray/builtin_checks.py:404: error: Unused "type: ignore" comment [unused-ignore]
+ pandera/backends/pandas/builtin_checks.py:195: error: Unused "type: ignore" comment [unused-ignore]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/formats/style.py:4410: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/io/formats/style.py:4421: error: Unused "type: ignore" comment [unused-ignore]
|
| _P = ParamSpec("_P") | ||
|
|
||
| _SupportsComparison: TypeAlias = SupportsDunderLE[Any] | SupportsDunderGE[Any] | SupportsDunderGT[Any] | SupportsDunderLT[Any] | ||
| # operator returns the rich comparison result without testing its truth value. |
There was a problem hiding this comment.
Are you trying to say "and this is why we define these protocols here rather than using the ones in _typeshed"? If so, you should say that explicitly in this comment; a casual reader of this stub won't necessarily know that there even are similar protocols defined in _typeshed
| # ordering methods are accepted. For example, if x.__lt__ has separate int and | ||
| # str overloads and y is int | str, neither overload accepts the whole union. | ||
| # The fallback accepts lt(x, y) because int and str each define an ordering method. | ||
| _ComparisonOperand: TypeAlias = _T | _SupportsComparison[Any] |
There was a problem hiding this comment.
I know that ty supports type aliases to bare typevars, but I'm not totally sure they're supported by all other type checkers; I think it would also be reasonable for a type checker to reject such a type alias as invalid. Have you double-checked that all major type checkers correctly infer this as a generic type alias?
| def le(a: _ComparisonOperand[_T], b: _SupportsComparison[_T], /) -> Any: ... | ||
|
|
||
| # Equality accepts any operands. Using Any also lets mypy infer a callable | ||
| # for a dispatch table containing both equality and ordering functions. |
There was a problem hiding this comment.
I have no idea what "dispatch table" is supposed to refer to here
| class _SupportsDunderGE(Protocol[_T_contra]): | ||
| def __ge__(self, other: _T_contra, /) -> object: ... | ||
|
|
||
| # Some projects use _SupportsComparison without a type argument. |
There was a problem hiding this comment.
I don't understand what this comment is trying to say
Since #16014,
operator.lt(x, y)can fail type checking even whenx < yis valid, whenx.__lt__(y)returns an object with no__bool__method. Python allowsx < yto return that object directly, andoperator.lt(x, y)has the same behavior.Also, the current stubs for
operator.lt,le,gt, andgerequire both operands to define an ordering method. Python only requires one operand to handle the comparison.Update
operator.lt,le,gt, andgeto accept ordering methods with arbitrary return types and allow heterogeneous operands where either side implements the comparison.Assisted by Codex.