Skip to content

Bug with comprehension inlining + type aliases #109194

Closed
@JelleZijlstra

Description

@JelleZijlstra

Consider this code:

class C:
    T = "class"
    type Alias3[T] = (T for _ in (1,))
    type Alias5[T] = [T for _ in (1,)]

print(list(C.Alias3.__value__))
print(C.Alias5.__value__)

On current main it produces:

[T]
['class']

So if you use a genexp, you get the T type parameter, but if you use a listcomp, you get the class variable. I think the genexp behavior is right; the comprehension should never see the class scope.

Found this while looking into #109118. Filing this separately as the symptom is different, but I suspect we'll have to solve both simultaneously. cc @carljm for PEP 709.

Metadata

Metadata

Assignees

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