Skip to content

TypeVar not constrained by default value (false negative #2711

@randolf-scholz

Description

@randolf-scholz

Describe the Bug

class Getter[T]:
    def get[S=None](self, default: S = None) -> T | S: ...

def test(arg: Getter[str]) -> None:
    result: str = arg.get() 
ERROR sandbox.py:2:40-44: Default `None` is not assignable to parameter `default` with type `S` [bad-function-definition]

I believe this is both a false positive on line 2 and a false negative on line 5. See python/typing#2213

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQDiMALizAE4DaAKgLqIAOunqj6mGGHoBzVlwDKAXgByudDD4AKODChgANOMmoArlBaJ68%2Bovqr1ASnoBaAHz0e9AD5XLhf6IAxPQA8gDSwsISUuxwLJqoHNKWzGycXHEcfE5udmowQiJiHPBmFvSZNvSJ0oSy8U70wQCilpU%2B9jD06Lgs1XQQ0uio2LD0LLgVLBwg%2BiAmLNBwJOSIIMEAqotQECyk9GAm6JSLanCRWJIHuBwAtqgsAProJrfYnJr4lhDoLDnumUKYnoJRYJg4IjAghAyle7w4lmA%2BAAvtDhLMQGQSmAoKRCBNblAKMEAAqkbG4ioYHAEeiUNSQaTgh4QNSEYTBeQwLoACzYxDgiAA9EKsZJcYQbtIhTB0ELMLhKHAhfT0Izmac5dcONUAG6oaAjMaq9UcFlqei4Yia5bCMgsHlqZy6zhwVkiWzQgDMhAAjF60egQMi5qgThAXQAxaAwChoLB4IhkYNAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions