Skip to content

Commit f6e2e58

Browse files
docs: remove broken LiteralString overloads example (closes #2090) (#2311)
docs: remove broken LiteralString overloads example 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: #2090
1 parent ddb5107 commit f6e2e58

1 file changed

Lines changed: 1 addition & 26 deletions

File tree

docs/spec/literal.rst

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Literal types. For example::
309309

310310
**Note:** If the user wants their API to support accepting both literals
311311
*and* the original type -- perhaps for legacy purposes -- they should
312-
implement a fallback overload. See :ref:`literalstring-overloads`.
312+
implement a fallback overload.
313313

314314
Interactions with other types and features
315315
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -777,28 +777,3 @@ Standard containers like ``List`` work as expected:
777777
::
778778

779779
xs: List[LiteralString] = ["foo", "bar", "baz"]
780-
781-
782-
.. _literalstring-overloads:
783-
784-
Interactions with Overloads
785-
"""""""""""""""""""""""""""
786-
787-
Literal strings and overloads do not need to interact in a special
788-
way: the existing rules work fine. ``LiteralString`` can be used as a
789-
fallback overload where a specific ``Literal["foo"]`` type does not
790-
match:
791-
792-
::
793-
794-
@overload
795-
def foo(x: Literal["foo"]) -> int: ...
796-
@overload
797-
def foo(x: LiteralString) -> bool: ...
798-
@overload
799-
def foo(x: str) -> str: ...
800-
801-
x1: int = foo("foo") # First overload.
802-
x2: bool = foo("bar") # Second overload.
803-
s: str
804-
x3: str = foo(s) # Third overload.

0 commit comments

Comments
 (0)