Skip to content

Accessing type arguments inside __init__ #519

@mitar

Description

@mitar

It seems this is not possible?

Example:

import typing

T = typing.TypeVar('T')

class Foo(typing.Generic[T]):
    def __init__(self):
        print(type(self).__args__)

A = Foo[int]
A()

I would expect that this prints out int as __args__, but it does not. It seems because runtime class is Foo, not Foo[int].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions