Skip to content

Is it still necessary to prohibit generics at runtime? #303

Closed
@ilevkivskyi

Description

@ilevkivskyi

There is a paragraph in PEP 484:

You cannot use the subscripted class (e.g. ``Node[int]``) directly in
an expression -- you must define a type alias.  (This restriction
exists because creating the subscripted class, e.g. ``Node[int]``, is
an expensive operation -- usually many times as expensive as
constructing an instance of it.  Using a type alias is also more
readable.)

However, __getitem__ is cached for generics now and this leads to significant speedup (Guido reported up to 300x speedup in extreme cases). I think the above restriction is not necessary anymore and could be removed from the PEP.

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