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

`np.float64` is not accepted as `float` under static type checks · Issue #21906 · numpy/numpy · GitHub

/ numpy Public

np.float64 is not accepted as float under static type checks #21906

Description

Some of the built-in scalar types inherit from the corresponding Python types. However, this fact does not seem to be exposed by the numpy type stubs.

# Python version 3.8.10, numpy version 1.23.0
import numpy as np

x = np.float64(1.0)
print(f"x={x} of type={type(x)} is float: {isinstance(x, float)}")
# x=1.0 of type=<class 'numpy.float64'> is float: True


def f(a: float) -> float:
    return a


f(x)
"""
pyright 1.1.256:
error: Argument of type "float64" cannot be assigned to parameter "a" of type "float" in function "f"
  "float64" is incompatible with "float" (reportGeneralTypeIssues)

mypy 0.961:
error: Argument 1 to "f" has incompatible type "floating[_64Bit]"; expected "float"
"""

Replacing np.float64 with np.float_ or np.double does not help.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL