Skip to content

isinstance(x, np.uint64) gives error: Second argument to "isinstance" must be a class or tuple of classes, TypeVar or generic type with type arguments not allowed #3830

Closed
@ischurov

Description

Environment data

  • Language Server version: 2023.1.10
  • OS and version: linux x64
  • Python version (and distribution if applicable, e.g. Anaconda): Python 3.10.8 (Anaconda)
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: basic

Code Snippet

import numpy as np

def foo(x):
    if not isinstance(x, np.uint64):
        x = np.uint64(x)
    return x

Repro Steps

Type-check the given snippet.

Expected behavior

No errors found.

Actual behavior

The following error is given regarding the expression `isinstance(x, np.uint64)`:
Second argument to "isinstance" must be a class or tuple of classes
  TypeVar or generic type with type arguments not allowed

Additional context

There is a similar fixed issue #2128. I am not sure that it is actually a bug, as np.uint64 is a type alias, but I believe there should be a way to run this `isinstance` without having type error. `mypy` finds no issues in this snippet.

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions