You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
max: comparing int with Decimal doesn't typecheck #5275
We could probably work around this in typeshed for the 2-arity case of max() by using a separate type var for the arguments and returning an union. The base problem is that mypy looks for a common base type in case like this, though, and only finds object. In my opinion it would be preferable to experiment with what happens if mypy would infer a union instead.
This is arguably a bug / limitation in mypy rather than a problem with the typeshed definition. The problem is that mypy uses a "join" operation to widen types in its type constraint solver rather than using a union operation.
The above sample type checks fine with pyright, which uses unions to widen types in its constraint solver. The return type of the call to max is int | Decimal.
Activity
srittau commentedon May 1, 2021
We could probably work around this in typeshed for the 2-arity case of
max()by using a separate type var for the arguments and returning an union. The base problem is that mypy looks for a common base type in case like this, though, and only findsobject. In my opinion it would be preferable to experiment with what happens if mypy would infer a union instead.erictraut commentedon May 2, 2021
This is arguably a bug / limitation in mypy rather than a problem with the typeshed definition. The problem is that mypy uses a "join" operation to widen types in its type constraint solver rather than using a union operation.
The above sample type checks fine with pyright, which uses unions to widen types in its constraint solver. The return type of the call to
maxisint | Decimal.srittau commentedon May 2, 2021
Eric explained it better than me. I don't think we should change the stubs in this case.