python / python/mypy

Standalone subscripted alias expression fails mypy check

Open
#13,337 3 comments 1 reaction 1 assignee View on GitHub

@sobolevn is already working on this.

Since Aug 11, 2022.

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

Description

Bug Report

Standalone subscripted alias expression raises the error "Type application is only supported for generic classes"

To Reproduce

Here's a reproducible playground link: https://mypy-play.net/?mypy=0.971&python=3.10&gist=e262d3dd99f2a708e96eb28338792632

Code:

T = TypeVar("T")
OptionalT: TypeAlias = Optional[T]
OptionalT[int] # error: Type application is only supported for generic classes

Expected Behavior

I was surprised that you couldn't have a free expression of the subscripted generic type alias. Standalone expressions like Optional[int] obviously work, as does X where X: TypeAlias = int.

Actual Behavior

The free expression gives the error: Type application is only supported for generic classes in the playground

Your Environment

The environment is python 3.10, mypy 0.971.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.