python / python/mypy

Subscript op on TypeAlias to Enum is misinterpreted

Open
#14,317 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Scanning code that makes use of an alias for an Enum class flags an error.

I see several similar issues in the GitHub issue list, e.g.
https://github.com/python/mypy/issues/14281
https://github.com/python/mypy/issues/13337

The error messages in those tickets is different however.

To Reproduce
Gist

Expected Behavior

No error

Actual Behavior

main.py:14: error: Type application targets a non-generic function or class
main.py:14: error: Variable "name" is not valid as a type
main.py:14: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Found 2 errors in 1 file (checked 1 source file)
Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.6.9 (I know, I know)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Gist and reproduce the reported diagnostics using mypy 0.971, then trace how the checker resolves the Enum type alias and subscript expression. Done means the reproduction produces no error while preserving correct handling of non-generic types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.