Skip to content

Let "Literal" accept another Literal type variable #10026

Open
@xuhdev

Description

@xuhdev

Feature

Currently Literal doesn't accept another Literal or Final[Literal]. For example:

from typing_extensions import Final, Literal

s: Final[Literal['ccc']] = 'ccc'
s1: Literal[s] = s

outputs:

a.py:4: error: Parameter 1 of Literal[...] is invalid
a.py:4: error: Variable "a.s" is not valid as a type
a.py:4: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
Found 2 errors in 1 file (checked 1 source file)

Pitch

This is particularly useful when there are some defined constants and people refer to those constants rather than the actual value. For example, some of these socket constants: https://docs.python.org/3/library/socket.html#socket.BDADDR_ANY

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions