Skip to content

Contextmanager lossing Generics #1646

@PabloRuizCuevas

Description

@PabloRuizCuevas

Describe the Bug

when using generics inside a contextmanager the generic is lost

from contextlib import contextmanager
from typing import Iterator


@contextmanager
def add_source_channel[T](source: list[T]) -> Iterator[list[T]]: ...

t: list[int] = [1]
m = add_source_channel(t) # not working  ->  _GeneratorContextManager[list[Unknown], None, None] 
# should be _GeneratorContextManager[list[int], None, None] 


def add_source_channel2[T](source: list[T]) -> Iterator[list[T]]: ...

m = add_source_channel2(t) # working just fine

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEAxrugC4z4tQTZ0Q3G5KLRszYcaGVAHMYlADrow1ei1LEI6Kb36DhASTaVULQQrPoAAk1bsWE9NNkLMMMHVSZMAfTi4ArpQMMF4MABYY6DBQANoAKgC6ABS%2BAUGIdFxwLHHxAJR0ALQAfHQGssaC0ZnZCfHphA3mLOnV0Ros8XQAvHTRAIzxCvQ9Ht4pgcFhEVGJLLnmzq7unj7%2BEyHh6JFQAEw5yWtpGRBZOfnFpYYVlFUnNfF1dA2E5sPLY4eTm9s7s-PoIAANCA-CxoHASORECAAMR0ACqYK4qjoYD86AYYOYcHMLjcYEEEhYXnQfho2FkiXw6Xa5xKWUoiAUdBZdEoMBYAXQqLkIAAcmSKYy6MB8ABfXkKIEgMjssBQUiEEw0KAUOEABVIcoVdDQWDw%2BBEiggUgCxggzBe6DhAGUYDA6KEWCxiHBEAB6d2y1wKwiCKTumDod2YXAMODu6yQU1GLHB1GCdwAN1Q0FQ2FgRujZrjdFwxDjEIUZBYoWYBSTsjgFu5PV5AGZCH0dpKAWLgahMRBKwAxaAwCh6nAESEgMVAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions