From 17b1ab2c8409321c1369fa8f41db56000ed7e054 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sun, 1 Feb 2026 21:26:03 -0800 Subject: [PATCH] Get more test cases ready for --local-partial-types --- test-data/unit/check-basic.test | 7 ++-- test-data/unit/check-callable.test | 10 +++-- test-data/unit/check-errorcodes.test | 13 +++--- test-data/unit/check-functions.test | 2 - test-data/unit/check-incremental.test | 4 +- test-data/unit/check-inference.test | 57 ++++++++++++++++++++++++--- test-data/unit/check-literal.test | 4 -- test-data/unit/check-protocols.test | 1 + 8 files changed, 72 insertions(+), 26 deletions(-) diff --git a/test-data/unit/check-basic.test b/test-data/unit/check-basic.test index bfd5e4e59303a..c2818b27b007d 100644 --- a/test-data/unit/check-basic.test +++ b/test-data/unit/check-basic.test @@ -369,9 +369,10 @@ def foo( pass [case testNoneHasBool] -none = None -b = none.__bool__() -reveal_type(b) # N: Revealed type is "Literal[False]" +def main() -> None: + none = None + b = none.__bool__() + reveal_type(b) # N: Revealed type is "Literal[False]" [builtins fixtures/bool.pyi] [case testAssignmentInvariantNoteForList] diff --git a/test-data/unit/check-callable.test b/test-data/unit/check-callable.test index f3ec6ec5f939d..d2cf6fa84f43b 100644 --- a/test-data/unit/check-callable.test +++ b/test-data/unit/check-callable.test @@ -500,11 +500,13 @@ if callable(): # E: Missing positional argument "x" in call to "callable" [builtins fixtures/callable.pyi] -[case testCallableWithNoneArgs] +[case testCallableWithAnyArgs] -fn = None -if callable(fn): - fn() +def main(fn: object) -> None: + if callable(fn): + fn() + fn(1, 2, 3) + fn(take="that") [builtins fixtures/callable.pyi] diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 58f48144b3e56..8533dbc6c56c4 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -534,7 +534,8 @@ d: D = {'x': 1, 'y': 2} # type: ignore[typeddict-item] [typing fixtures/typing-typeddict.pyi] [case testErrorCodeCannotDetermineType] -y = x # E: Cannot determine type of "x" [has-type] # E: Name "x" is used before definition [used-before-def] +y = x # E: Cannot determine type of "x" [has-type] \ + # E: Name "x" is used before definition [used-before-def] reveal_type(y) # N: Revealed type is "Any" x = None @@ -598,15 +599,15 @@ from typing import Callable def f() -> None: pass -x = f() # E: "f" does not return a value (it only ever returns None) [func-returns-value] - class A: def g(self) -> None: pass -y = A().g() # E: "g" of "A" does not return a value (it only ever returns None) [func-returns-value] - c: Callable[[], None] -z = c() # E: Function does not return a value (it only ever returns None) [func-returns-value] + +def main() -> None: + x = f() # E: "f" does not return a value (it only ever returns None) [func-returns-value] + y = A().g() # E: "g" of "A" does not return a value (it only ever returns None) [func-returns-value] + z = c() # E: Function does not return a value (it only ever returns None) [func-returns-value] [case testErrorCodeInstantiateAbstract] from abc import abstractmethod diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index a0762ab78f482..ed2948ccddedc 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -2630,7 +2630,6 @@ x_in = None def Y(x: Optional[str] = X(x_in)): ... xx: Optional[int] = X(x_in) -[out] [case testNoComplainInferredNoneStrict] from typing import TypeVar, Optional @@ -2640,7 +2639,6 @@ x_in = None def Y(x: Optional[str] = X(x_in)): ... xx: Optional[int] = X(x_in) -[out] [case testNoComplainNoneReturnFromUntyped] def foo() -> None: diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index c1df11570bcf1..1698a51a975d9 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -7256,14 +7256,14 @@ tmp/impl.py:7: error: Argument 1 has incompatible type "str"; expected "int" [file foo.py] foo = 5 [file foo.py.2] -foo = None +foo = "foo" [file bar.py] from foo import foo bar: int = foo [out] [out2] [out3] -tmp/bar.py:2: error: Incompatible types in assignment (expression has type "None", variable has type "int") +tmp/bar.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int") [case testIncrementalBlockingErrorRepeatAndUndo] import m diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 81462aad40e9d..22edd12b0c4ca 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -1153,7 +1153,7 @@ for xx, yy, zz in [(A(), B())]: # E: Need more than 2 values to unpack (3 expect pass for xx, (yy, zz) in [(A(), B())]: # E: "B" object is not iterable pass -for xxx, yyy in [(None, None)]: +for xxx, yyy in [(1, 2)]: pass [builtins fixtures/for.pyi] @@ -2125,19 +2125,66 @@ main:6: error: Incompatible types in assignment (expression has type "int", vari main:7: error: "None" not callable [case testGlobalInitializedToNoneSetFromFunction] +# flags: --no-local-partial-types a = None -def f(): +def f() -> None: global a a = 42 -[out] + reveal_type(a) # N: Revealed type is "builtins.int" +reveal_type(a) # N: Revealed type is "builtins.int | None" + +b = None +def unchecked(): + global b + b = 42 +reveal_type(b) # N: Revealed type is "Any | None" + +[case testGlobalInitializedToNoneSetFromFunctionLocalPartialTypes] +# flags: --local-partial-types +a = None # E: Need type annotation for "a" (hint: "a: | None = ...") +def f() -> None: + global a + a = 42 + reveal_type(a) # N: Revealed type is "builtins.int" +reveal_type(a) # N: Revealed type is "None" + +b = None # E: Need type annotation for "b" (hint: "b: | None = ...") +def unchecked(): + global b + b = 42 +reveal_type(b) # N: Revealed type is "None" [case testGlobalInitializedToNoneSetFromMethod] +# flags: --no-local-partial-types a = None class C: - def m(self): + def m(self) -> None: global a a = 42 -[out] +reveal_type(a) # N: Revealed type is "builtins.int | None" + +b = None +class CC: + def unchecked(self): + global b + b = 42 +reveal_type(b) # N: Revealed type is "Any | None" + +[case testGlobalInitializedToNoneSetFromMethodLocalPartialTypes] +# flags: --local-partial-types +a = None # E: Need type annotation for "a" (hint: "a: | None = ...") +class C: + def m(self) -> None: + global a + a = 42 +reveal_type(a) # N: Revealed type is "None" + +b = None # E: Need type annotation for "b" (hint: "b: | None = ...") +class CC: + def unchecked(self): + global b + b = 42 +reveal_type(b) # N: Revealed type is "None" -- More partial type errors -- ------------------------ diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index 357b74953415a..0b779f57b6150 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -1013,7 +1013,6 @@ reveal_type(none1) # N: Revealed type is "None" reveal_type(none2) # N: Revealed type is "None" reveal_type(none3) # N: Revealed type is "None" [builtins fixtures/primitives.pyi] -[out] [case testLiteralInferredOnlyForActualLiterals] from typing import Literal @@ -1054,7 +1053,6 @@ combined = g combined = h [builtins fixtures/primitives.pyi] -[out] [case testLiteralInferredTypeMustMatchExpected] from typing import Literal @@ -1068,7 +1066,6 @@ e: Literal["foo", "bar"] = "baz" # E: Incompatible types in assignment (expre f: Literal[True, 4] = False # E: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True, 4]") [builtins fixtures/primitives.pyi] -[out] [case testLiteralInferredInCall] from typing import Literal @@ -1114,7 +1111,6 @@ f_none_lit(None) f_none(None) f_none_lit(n1) [builtins fixtures/primitives.pyi] -[out] [case testLiteralInferredInReturnContext] from typing import Literal diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 5dc10b9736c43..c30d972b67c42 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -1467,6 +1467,7 @@ def f(x: Callable[[T, T], None]) -> T: pass def g(x: P, y: P2) -> None: pass x = f(g) reveal_type(x) # N: Revealed type is "None" + [case testMeetProtocolWithNormal] from typing import Protocol, Callable, TypeVar