Skip to content

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

Closed

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.

Activity

  1. gvanrossum commented on Oct 18, 2016

    @gvanrossum
    Member

    However mypy still prohibits it. I'd much rather remove this from mypy and leave it in the PEP than the other way around. ;-)

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions