Skip to content

The result of get_origin() on a GenericAlias variable "is not indexable" #18894

Not planned
@mgorny

Description

@mgorny

Bug Report

Consider the following minimal snippet:

from types import GenericAlias
from typing import get_origin


def test(expected_type: GenericAlias) -> None:
    list_type = get_origin(expected_type)
    list_type[int]

mypy seems to consider list_type[int] invalid here:

$ mypy foo.py 
foo.py:7: error: Value of type "type" is not indexable  [index]
Found 1 error in 1 file (checked 1 source file)

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=d8185597c8fe9a327a276508cc1fa4d3

Actual Behavior

$ mypy foo.py 
foo.py:7: error: Value of type "type" is not indexable  [index]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.13.2

Activity

A5rocks

A5rocks commented on Apr 8, 2025

@A5rocks
Collaborator

I think this is moreso a typeshed thing. Probably they just need to add an overload or two?

hauntsaninja

hauntsaninja commented on May 30, 2025

@hauntsaninja
Collaborator

Yeah, if there is a bug here, it should be handled in typeshed. In general, static type checking of runtime typing is kind of hard to do in Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mgorny@hauntsaninja@A5rocks

        Issue actions

          The result of `get_origin()` on a `GenericAlias` variable "is not indexable" · Issue #18894 · python/mypy