Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive on numpy.mgrid #11185

Closed
Brow71189 opened this issue Sep 24, 2021 · 1 comment
Closed

False positive on numpy.mgrid #11185

Brow71189 opened this issue Sep 24, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@Brow71189
Copy link

Brow71189 commented Sep 24, 2021

Bug Report

The following code triggers a mypy type checking failure:

import numpy

numpy.mgrid[0:10:1j]

Mypy reports "Slice index must be an integer or None" on this code snippet.

Admittedly this is a special case, because numpy.mgrid does not get "called" with parenthesis but square brackets. But a complex number as the third argument to mgrid is valid code and has a special meaning (it makes mgrid create an array with this many entries). See also: https://numpy.org/doc/stable/reference/generated/numpy.mgrid.html

EDIT:

numpy.mgrid also allows floats for the first two "slices", which also triggers a mypy error:

import numpy

numpy.mgrid[-1.5: 1.5]

To Reproduce

Type check the above code snippet with mypy.

Expected Behavior

The above code should pass type checking.

Actual Behavior

Mypy reports "Slice index must be an integer or None".

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9.7
  • Operating system and version: Windows 10
  • numpy version: 1.20.3
@Brow71189 Brow71189 added the bug mypy got something wrong label Sep 24, 2021
@ethanhs
Copy link
Collaborator

ethanhs commented Sep 24, 2021

Duplicate of #2410

@ethanhs ethanhs marked this as a duplicate of #2410 Sep 24, 2021
@ethanhs ethanhs closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants