Skip to content

None is not a possible value for type variable bound to optional value?! #14754

@NeilGirdhar

Description

@NeilGirdhar
from typing import TypeVar

class X: pass
U = TypeVar('U', bound=None | X)

def project(projectable: U) -> U:
    if projectable is None:
        return None  # MyPy claims this is unreachable!
    return projectable

If warn-unreachable is enabled, then MyPy claims this is unreachable.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions