Any is not subscriptable
Open
Nobody has claimed this yet.
bug
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When treating Any as one would treat Union by subscripting values, i.e. Any[int,str], mypy does not produce an error or failure of any kind.
To Reproduce
- Create file
test.pywith the contents:
from typing import Any
test: Any[int,str] = "Test"
print(test)
- Run
mypy test.py, observe no failure - Run python test
python test.py, observe failure:
Traceback (most recent call last):
File "test.py", line 3, in <module>
test: Any[int,str] = "Test"
File "/home/chad/.pyenv/versions/3.8.5/lib/python3.8/typing.py", line 261, in inner
return func(*args, **kwds)
File "/home/chad/.pyenv/versions/3.8.5/lib/python3.8/typing.py", line 370, in __getitem__
raise TypeError(f"{self} is not subscriptable")
TypeError: typing.Any is not subscriptable
Expected Behavior
Expect mypy to identify erroneous use of Any and raise error
Actual Behavior
No errors
Your Environment
- Mypy version used: 0.902
- Mypy command-line flags: --all
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:
[mypy]
python_version = 3.8
ignore_missing_imports = True
- Operating system and version: Linux chad-a15 5.8.0-55-generic #62~20.04.1-Ubuntu SMP Wed Jun 2 08:55:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided test.py reproducer and inspect mypy's handling of subscripted types involving Any. Add a regression test that captures the expected diagnostic, then run the relevant test suite to confirm mypy reports the invalid use while preserving valid Any usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100