Skip to content

Commit e63e6e5

Browse files
authored
Get more test cases ready for --local-partial-types (#20718)
Some of this was done in #18377
1 parent ec4c463 commit e63e6e5

File tree

8 files changed

+72
-26
lines changed

8 files changed

+72
-26
lines changed

test-data/unit/check-basic.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,10 @@ def foo(
369369
pass
370370

371371
[case testNoneHasBool]
372-
none = None
373-
b = none.__bool__()
374-
reveal_type(b) # N: Revealed type is "Literal[False]"
372+
def main() -> None:
373+
none = None
374+
b = none.__bool__()
375+
reveal_type(b) # N: Revealed type is "Literal[False]"
375376
[builtins fixtures/bool.pyi]
376377

377378
[case testAssignmentInvariantNoteForList]

test-data/unit/check-callable.test

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,13 @@ if callable(): # E: Missing positional argument "x" in call to "callable"
500500

501501
[builtins fixtures/callable.pyi]
502502

503-
[case testCallableWithNoneArgs]
503+
[case testCallableWithAnyArgs]
504504

505-
fn = None
506-
if callable(fn):
507-
fn()
505+
def main(fn: object) -> None:
506+
if callable(fn):
507+
fn()
508+
fn(1, 2, 3)
509+
fn(take="that")
508510

509511
[builtins fixtures/callable.pyi]
510512

test-data/unit/check-errorcodes.test

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ d: D = {'x': 1, 'y': 2} # type: ignore[typeddict-item]
534534
[typing fixtures/typing-typeddict.pyi]
535535

536536
[case testErrorCodeCannotDetermineType]
537-
y = x # E: Cannot determine type of "x" [has-type] # E: Name "x" is used before definition [used-before-def]
537+
y = x # E: Cannot determine type of "x" [has-type] \
538+
# E: Name "x" is used before definition [used-before-def]
538539
reveal_type(y) # N: Revealed type is "Any"
539540
x = None
540541

@@ -598,15 +599,15 @@ from typing import Callable
598599

599600
def f() -> None: pass
600601

601-
x = f() # E: "f" does not return a value (it only ever returns None) [func-returns-value]
602-
603602
class A:
604603
def g(self) -> None: pass
605604

606-
y = A().g() # E: "g" of "A" does not return a value (it only ever returns None) [func-returns-value]
607-
608605
c: Callable[[], None]
609-
z = c() # E: Function does not return a value (it only ever returns None) [func-returns-value]
606+
607+
def main() -> None:
608+
x = f() # E: "f" does not return a value (it only ever returns None) [func-returns-value]
609+
y = A().g() # E: "g" of "A" does not return a value (it only ever returns None) [func-returns-value]
610+
z = c() # E: Function does not return a value (it only ever returns None) [func-returns-value]
610611

611612
[case testErrorCodeInstantiateAbstract]
612613
from abc import abstractmethod

test-data/unit/check-functions.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,6 @@ x_in = None
26302630
def Y(x: Optional[str] = X(x_in)): ...
26312631

26322632
xx: Optional[int] = X(x_in)
2633-
[out]
26342633

26352634
[case testNoComplainInferredNoneStrict]
26362635
from typing import TypeVar, Optional
@@ -2640,7 +2639,6 @@ x_in = None
26402639
def Y(x: Optional[str] = X(x_in)): ...
26412640

26422641
xx: Optional[int] = X(x_in)
2643-
[out]
26442642

26452643
[case testNoComplainNoneReturnFromUntyped]
26462644
def foo() -> None:

test-data/unit/check-incremental.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7256,14 +7256,14 @@ tmp/impl.py:7: error: Argument 1 has incompatible type "str"; expected "int"
72567256
[file foo.py]
72577257
foo = 5
72587258
[file foo.py.2]
7259-
foo = None
7259+
foo = "foo"
72607260
[file bar.py]
72617261
from foo import foo
72627262
bar: int = foo
72637263
[out]
72647264
[out2]
72657265
[out3]
7266-
tmp/bar.py:2: error: Incompatible types in assignment (expression has type "None", variable has type "int")
7266+
tmp/bar.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int")
72677267

72687268
[case testIncrementalBlockingErrorRepeatAndUndo]
72697269
import m

test-data/unit/check-inference.test

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ for xx, yy, zz in [(A(), B())]: # E: Need more than 2 values to unpack (3 expect
11531153
pass
11541154
for xx, (yy, zz) in [(A(), B())]: # E: "B" object is not iterable
11551155
pass
1156-
for xxx, yyy in [(None, None)]:
1156+
for xxx, yyy in [(1, 2)]:
11571157
pass
11581158
[builtins fixtures/for.pyi]
11591159

@@ -2125,19 +2125,66 @@ main:6: error: Incompatible types in assignment (expression has type "int", vari
21252125
main:7: error: "None" not callable
21262126

21272127
[case testGlobalInitializedToNoneSetFromFunction]
2128+
# flags: --no-local-partial-types
21282129
a = None
2129-
def f():
2130+
def f() -> None:
21302131
global a
21312132
a = 42
2132-
[out]
2133+
reveal_type(a) # N: Revealed type is "builtins.int"
2134+
reveal_type(a) # N: Revealed type is "builtins.int | None"
2135+
2136+
b = None
2137+
def unchecked():
2138+
global b
2139+
b = 42
2140+
reveal_type(b) # N: Revealed type is "Any | None"
2141+
2142+
[case testGlobalInitializedToNoneSetFromFunctionLocalPartialTypes]
2143+
# flags: --local-partial-types
2144+
a = None # E: Need type annotation for "a" (hint: "a: <type> | None = ...")
2145+
def f() -> None:
2146+
global a
2147+
a = 42
2148+
reveal_type(a) # N: Revealed type is "builtins.int"
2149+
reveal_type(a) # N: Revealed type is "None"
2150+
2151+
b = None # E: Need type annotation for "b" (hint: "b: <type> | None = ...")
2152+
def unchecked():
2153+
global b
2154+
b = 42
2155+
reveal_type(b) # N: Revealed type is "None"
21332156

21342157
[case testGlobalInitializedToNoneSetFromMethod]
2158+
# flags: --no-local-partial-types
21352159
a = None
21362160
class C:
2137-
def m(self):
2161+
def m(self) -> None:
21382162
global a
21392163
a = 42
2140-
[out]
2164+
reveal_type(a) # N: Revealed type is "builtins.int | None"
2165+
2166+
b = None
2167+
class CC:
2168+
def unchecked(self):
2169+
global b
2170+
b = 42
2171+
reveal_type(b) # N: Revealed type is "Any | None"
2172+
2173+
[case testGlobalInitializedToNoneSetFromMethodLocalPartialTypes]
2174+
# flags: --local-partial-types
2175+
a = None # E: Need type annotation for "a" (hint: "a: <type> | None = ...")
2176+
class C:
2177+
def m(self) -> None:
2178+
global a
2179+
a = 42
2180+
reveal_type(a) # N: Revealed type is "None"
2181+
2182+
b = None # E: Need type annotation for "b" (hint: "b: <type> | None = ...")
2183+
class CC:
2184+
def unchecked(self):
2185+
global b
2186+
b = 42
2187+
reveal_type(b) # N: Revealed type is "None"
21412188

21422189
-- More partial type errors
21432190
-- ------------------------

test-data/unit/check-literal.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,6 @@ reveal_type(none1) # N: Revealed type is "None"
10131013
reveal_type(none2) # N: Revealed type is "None"
10141014
reveal_type(none3) # N: Revealed type is "None"
10151015
[builtins fixtures/primitives.pyi]
1016-
[out]
10171016

10181017
[case testLiteralInferredOnlyForActualLiterals]
10191018
from typing import Literal
@@ -1054,7 +1053,6 @@ combined = g
10541053
combined = h
10551054

10561055
[builtins fixtures/primitives.pyi]
1057-
[out]
10581056

10591057
[case testLiteralInferredTypeMustMatchExpected]
10601058
from typing import Literal
@@ -1068,7 +1066,6 @@ e: Literal["foo", "bar"] = "baz" # E: Incompatible types in assignment (expre
10681066
f: Literal[True, 4] = False # E: Incompatible types in assignment (expression has type "Literal[False]", variable has type "Literal[True, 4]")
10691067

10701068
[builtins fixtures/primitives.pyi]
1071-
[out]
10721069

10731070
[case testLiteralInferredInCall]
10741071
from typing import Literal
@@ -1114,7 +1111,6 @@ f_none_lit(None)
11141111
f_none(None)
11151112
f_none_lit(n1)
11161113
[builtins fixtures/primitives.pyi]
1117-
[out]
11181114

11191115
[case testLiteralInferredInReturnContext]
11201116
from typing import Literal

test-data/unit/check-protocols.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ def f(x: Callable[[T, T], None]) -> T: pass
14671467
def g(x: P, y: P2) -> None: pass
14681468
x = f(g)
14691469
reveal_type(x) # N: Revealed type is "None"
1470+
14701471
[case testMeetProtocolWithNormal]
14711472
from typing import Protocol, Callable, TypeVar
14721473

0 commit comments

Comments
 (0)