Skip to content

float not understood as numbers.Number #7375

Closed
@jordan-schneider

Description

@jordan-schneider

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request? Reporting a bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
import numbers

a: float = 5.0
print(isinstance(a, numbers.Number))  # True

def f(a: float) -> numbers.Number:
    return a  # Incompatible return value type (got "float", expected "Number")
  • What is the actual behavior/output?
    Mypy reports the error "Incompatible return value type (got "float", expected "Number")".
  • What is the behavior/output you expect?
    I expect mypy to report no errors.
  • What are the versions of mypy and Python you are using?
    mypy 0.660
    Python 3.6.8
    Do you see the same issue after installing mypy from Git master?
    Yes.
  • What are the mypy flags you are using? (For example --strict-optional)
    None.

I'm slightly unclear if this is really a bug because I don't really understand what numbers is doing but isinstance() returns true, so I would expect the above code to be fine.

Thanks!

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