From fbb5c8aa3c19891f2a6d78ccf335ae91c94f98ca Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 29 Dec 2025 14:59:19 +0000 Subject: [PATCH] [ty] Fix `LiteralString` import in `ty_extensions.pyi` (#22244) --- crates/ty_ide/src/goto_type_definition.rs | 50 ++-- crates/ty_ide/src/inlay_hints.rs | 240 +++++++++--------- .../resources/mdtest/call/function.md | 1 + .../ty_extensions/ty_extensions.pyi | 10 +- 4 files changed, 148 insertions(+), 153 deletions(-) diff --git a/crates/ty_ide/src/goto_type_definition.rs b/crates/ty_ide/src/goto_type_definition.rs index e6cf468c87..35a76b4cee 100644 --- a/crates/ty_ide/src/goto_type_definition.rs +++ b/crates/ty_ide/src/goto_type_definition.rs @@ -179,13 +179,13 @@ mod tests { | ^^ Clicking here | info: Found 1 type definition - --> stdlib/ty_extensions.pyi:21:1 + --> stdlib/ty_extensions.pyi:15:1 | - 19 | # Types - 20 | Unknown = object() - 21 | AlwaysTruthy = object() + 13 | # Types + 14 | Unknown = object() + 15 | AlwaysTruthy = object() | ------------ - 22 | AlwaysFalsy = object() + 16 | AlwaysFalsy = object() | "); } @@ -883,13 +883,13 @@ mod tests { 4 | class MyClass: | info: Found 1 type definition - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ------- - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | "#); } @@ -938,13 +938,13 @@ mod tests { | ^^ Clicking here | info: Found 1 type definition - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ------- - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | "#); } @@ -965,13 +965,13 @@ mod tests { | ^^^^^^ Clicking here | info: Found 1 type definition - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ------- - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | "#); } @@ -1726,13 +1726,13 @@ def function(): | ^^^^^^ Clicking here | info: Found 1 type definition - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ------- - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | "); } diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index 9f6e2a5afe..86756f175a 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -1875,13 +1875,13 @@ mod tests { --------------------------------------------- info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:5:18 @@ -2234,13 +2234,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:2:10 @@ -2288,13 +2288,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:3:10 @@ -2363,13 +2363,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:4:10 @@ -2422,13 +2422,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:5:10 @@ -2481,13 +2481,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:6:10 @@ -2540,13 +2540,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:7:10 @@ -2599,13 +2599,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:8:10 @@ -2658,13 +2658,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:9:10 @@ -2716,13 +2716,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:10:10 @@ -2774,13 +2774,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:11:10 @@ -2847,13 +2847,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:12:10 @@ -3167,13 +3167,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:7:13 @@ -3303,13 +3303,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:8:19 @@ -3378,13 +3378,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:8:48 @@ -3529,13 +3529,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:9:13 @@ -3604,13 +3604,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:9:47 @@ -3754,13 +3754,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:10:13 @@ -3825,13 +3825,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:10:47 @@ -4286,13 +4286,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:3:10 @@ -4341,13 +4341,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:4:10 @@ -5304,13 +5304,13 @@ mod tests { bar([a=]1, [b=]2) --------------------------------------------- info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:2:14 @@ -5322,13 +5322,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:3:17 @@ -6154,13 +6154,13 @@ mod tests { | info[inlay-hint-location]: Inlay Hint Target - --> stdlib/ty_extensions.pyi:20:1 + --> stdlib/ty_extensions.pyi:14:1 | - 19 | # Types - 20 | Unknown = object() + 13 | # Types + 14 | Unknown = object() | ^^^^^^^ - 21 | AlwaysTruthy = object() - 22 | AlwaysFalsy = object() + 15 | AlwaysTruthy = object() + 16 | AlwaysFalsy = object() | info: Source --> main2.py:4:63 diff --git a/crates/ty_python_semantic/resources/mdtest/call/function.md b/crates/ty_python_semantic/resources/mdtest/call/function.md index a8526a453b..550d7920b2 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/function.md +++ b/crates/ty_python_semantic/resources/mdtest/call/function.md @@ -999,6 +999,7 @@ from ty_extensions import static_assert static_assert() # error: [too-many-positional-arguments] "Too many positional arguments to function `static_assert`: expected 2, got 3" +# error: [invalid-argument-type] "Argument to function `static_assert` is incorrect: Expected `LiteralString | None`, found `Literal[2]`" static_assert(True, 2, 3) ``` diff --git a/crates/ty_vendored/ty_extensions/ty_extensions.pyi b/crates/ty_vendored/ty_extensions/ty_extensions.pyi index 36e6c51b1f..ba3b1a1c45 100644 --- a/crates/ty_vendored/ty_extensions/ty_extensions.pyi +++ b/crates/ty_vendored/ty_extensions/ty_extensions.pyi @@ -3,15 +3,9 @@ import sys import types from collections.abc import Iterable from enum import Enum -from typing import ( - Any, - ClassVar, - LiteralString, - Protocol, - _SpecialForm, -) +from typing import Any, ClassVar, Protocol, _SpecialForm -from typing_extensions import Self # noqa: UP035 +from typing_extensions import LiteralString, Self # noqa: UP035 # Special operations def static_assert(condition: object, msg: LiteralString | None = None) -> None: ...