Skip to content

Lazy evaluation and PEP 649 #11

Open
@JelleZijlstra

Description

@JelleZijlstra

My current prototype evaluates TypeVar bounds eagerly:

>>> class Foo[FooT: x]: pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <generic parameters of Foo>
NameError: name 'x' is not defined

I haven't implemented type aliases yet, but the specification in the PEP says they should also be evaluated eagerly.

This means that you'd have to use quoted annotations in order to use forward references in these contexts (for example, for a class generic over a TypeVar bound to itself; or for mutually recursive generic aliases).

Given that PEP 649 is likely to be the future of annotations in general, this is problematic. PEP 649 should generally eliminate the need to quote annotations, but here we're introducing new contexts where quoted annotations are unavoidable.

Should we instead use a PEP 649-like mechanism to delay evaluation of TypeVar bounds and type alias values?

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