Skip to content

PEP696 + PEP749: Defer evaluation of defaults when parametrizing #144361

@randolf-scholz

Description

@randolf-scholz

Bug report

Bug description:

With PEP 696 + PEP 749, the following works just fine:

class Scalar[CompatT, TruthT = BoolScalar]: ...
class BoolScalar(Scalar): ...
class IntScalar(Scalar[int]): ...  # OK ✅️

However, if we switch around the order of definition, the code breaks:

class Scalar[CompatT, TruthT = BoolScalar]: ...
class IntScalar(Scalar[int]): ...  # ❌️ NameError: name 'BoolScalar' is not defined
class BoolScalar(Scalar): ...

I guess since the default gets evaluated here. Not sure whether this is a bug or feature request, but it would be nice if the evaluation of the default could be deferred in is case as well.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions