FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

max: comparing int with Decimal doesn't typecheck · Issue #5275 · python/typeshed · GitHub

Repository navigation

max: comparing int with Decimal doesn't typecheck #5275

Closed

Description

from decimal import Decimal

max(1, Decimal(2))

error: Value of type variable "SupportsLessThanT" of "max" cannot be "object"

I would expect this to pass.

Activity

  1. srittau commented on May 1, 2021

    Collaborator

    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.

  2. erictraut commented on May 2, 2021

    Contributor

    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.

  3. srittau commented on May 2, 2021

    Collaborator

    Eric explained it better than me. I don't think we should change the stubs in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL