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
Subtype (numpy.float64) is reported as incompatible with parent type (float) #4332
I would expect Pylance to not give any error messages for the above code snippet, as np.float64 is a subtype of python's native float type.
Actual behavior
Pylance reports the following error message:
Argument of type"float64" cannot be assigned to parameter "x" of type"float"infunction"idx""float64" is incompatible with "float" Pylance (reportGeneralTypeIssues)
However, the type stubs that are bundled with numpy don't define numpy.generic as a subtype of float. Rather, they define numpy.generic as derived from an internal class called numpy._ArrayOrScalarCommon which has no relationship to float. For this reason, a static type checker will not see float as being a subtype of numpy.float64.
Not surprisingly, mypy (a different static type checker) emits the same error as pylance in this case.
I don't know why the numpy authors have chosen to define numpy.generic in a way that deviates from the runtime. You may want to post a question in the numpy discussion forum.
Activity
erictraut commentedon May 9, 2023
At runtime,
numpy.float64has the following inheritance hierarchy:However, the type stubs that are bundled with numpy don't define
numpy.genericas a subtype offloat. Rather, they definenumpy.genericas derived from an internal class callednumpy._ArrayOrScalarCommonwhich has no relationship tofloat. For this reason, a static type checker will not seefloatas being a subtype ofnumpy.float64.Not surprisingly, mypy (a different static type checker) emits the same error as pylance in this case.
I don't know why the numpy authors have chosen to define
numpy.genericin a way that deviates from the runtime. You may want to post a question in the numpy discussion forum.