Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 6 additions & 4 deletions test-data/unit/check-callable.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
13 changes: 7 additions & 6 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 52 additions & 5 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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: <type> | 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: <type> | 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: <type> | 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: <type> | None = ...")
class CC:
def unchecked(self):
global b
b = 42
reveal_type(b) # N: Revealed type is "None"

-- More partial type errors
-- ------------------------
Expand Down
4 changes: 0 additions & 4 deletions test-data/unit/check-literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1054,7 +1053,6 @@ combined = g
combined = h

[builtins fixtures/primitives.pyi]
[out]

[case testLiteralInferredTypeMustMatchExpected]
from typing import Literal
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down