python / python/typing

Generic MRO

Open
#777 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: feature
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

Generic information are lost with classes __mro__. But it could be useful to have it, especially for #776 implementation.
typing module could integrate a generic_mro function in order to retrieve the class MRO annotated with related generic information; this function could also accept a generic alias in argument.

from typing import Generic, TypeVar, generic_mro

T = TypeVar("T")
class A(Generic[T]): ...

U = TypeVar("U")
class B(A[U]): ...

class C(B[int]):
    pass

assert generic_mro(C) == (C, B[int], A[int], Generic, object)
assert generic_mro(B) == (B, A[U], Generic, object)
assert generic_mro(B[int]) == (B[int], A[int], Generic, object)

Contributor guide

No contributing guide indexed for this repository

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 by reading the proposed generic_mro API and related issue #776; the issue names no implementation files or tests. Done means providing the proposed function and matching the three documented MRO results for C, B, and B[int].

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.