Skip to content

Colon slice behaves differently from built-in slice function #11640

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

Closed
gao462 opened this issue Nov 29, 2021 · 4 comments
Closed

Colon slice behaves differently from built-in slice function #11640

gao462 opened this issue Nov 29, 2021 · 4 comments
Labels
bug mypy got something wrong

Comments

@gao462
Copy link

gao462 commented Nov 29, 2021

Bug Report

Slice using colon notation has different behavior from slice using built-in slice function.

To Reproduce

Use colon notation will have error message.

import numpy as onp
import numpy.typing as onpt
imin: onpt.NDArray[onp.int64] = onp.array(0)
imax: onpt.NDArray[onp.int64] = onp.array(2)
M = onp.array([1.0, 2.0, 3.0, 4.0])
print(M[imin:imax])
error: Slice index must be an integer or None  [misc]
Found 1 error in 1 file (checked 1 source file)

But using built-in slice function has no problem.

import numpy as onp
import numpy.typing as onpt
imin: onpt.NDArray[onp.int64] = onp.array(0)
imax: onpt.NDArray[onp.int64] = onp.array(2)
M = onp.array([1.0, 2.0, 3.0, 4.0])
islice = slice(imin, imax)
print(M[islice])
Success: no issues found in 1 source file

Expected Behavior

Colon slice should has no error message as built-in slice function.

Actual Behavior

Colon slice has error message which is unexpected.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
plugins = "numpy.typing.mypy_plugin"
check_untyped_defs = true
disallow_any_generics = true
ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
no_implicit_reexport = false
  • Python version used: 3.9.7
  • Operating system and version: Linux
@gao462 gao462 added the bug mypy got something wrong label Nov 29, 2021
@sobolevn
Copy link
Member

sobolevn commented Dec 3, 2021

CC @Zac-HD

It might be related to the recent feature you were interested in 🙂

@Zac-HD
Copy link
Contributor

Zac-HD commented Dec 3, 2021

Nope, not related - my PR was type-level slicing, this is value-level.

@erictraut
Copy link

It looks like this bug has been fixed. I'm not able to repro the error using mypy 1.5.

@hauntsaninja
Copy link
Collaborator

I fixed this in #14738

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

5 participants