From c6889675d0d0b0ca7a3b434ba1248c8af8087c10 Mon Sep 17 00:00:00 2001 From: ashishpatel26 Date: Mon, 22 Jun 2026 18:06:18 +0530 Subject: [PATCH] docs: remove broken LiteralString overloads example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Interactions with Overloads" section under LiteralString contained an example that does not typecheck in pyright (and other checkers) because the `Literal["foo"]` and `LiteralString` overloads overlap unsafely. The section specified no normative behavior — it was purely illustrative — so the cleanest fix is to remove it. Also drop the `See :ref:\`literalstring-overloads\`` back-reference from the preceding Literal-type note, since the target no longer exists. Fixes: https://github.com/python/typing/issues/2090 --- docs/spec/literal.rst | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/docs/spec/literal.rst b/docs/spec/literal.rst index 7b0015ca3..0eb93c27a 100644 --- a/docs/spec/literal.rst +++ b/docs/spec/literal.rst @@ -309,7 +309,7 @@ Literal types. For example:: **Note:** If the user wants their API to support accepting both literals *and* the original type -- perhaps for legacy purposes -- they should -implement a fallback overload. See :ref:`literalstring-overloads`. +implement a fallback overload. Interactions with other types and features ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -777,28 +777,3 @@ Standard containers like ``List`` work as expected: :: xs: List[LiteralString] = ["foo", "bar", "baz"] - - -.. _literalstring-overloads: - -Interactions with Overloads -""""""""""""""""""""""""""" - -Literal strings and overloads do not need to interact in a special -way: the existing rules work fine. ``LiteralString`` can be used as a -fallback overload where a specific ``Literal["foo"]`` type does not -match: - -:: - - @overload - def foo(x: Literal["foo"]) -> int: ... - @overload - def foo(x: LiteralString) -> bool: ... - @overload - def foo(x: str) -> str: ... - - x1: int = foo("foo") # First overload. - x2: bool = foo("bar") # Second overload. - s: str - x3: str = foo(s) # Third overload.