Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added test case that checks for note when a union type with None does…
…n't have an attribute
  • Loading branch information
angelawuuu committed Apr 24, 2024
commit f31cf9c3ed9a8490785fb998332530b95c7f71ec
10 changes: 10 additions & 0 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ if int():

[builtins fixtures/isinstance.pyi]

[case testUnionAttributeAccessWithNoneItem]
from typing import Union

class A:
def foo(self) -> int: pass

def f(x: Union[A, None]) -> int:
return x.foo() # E: Item "None" of "Optional[A]" has no attribute "foo" \
# N: You can use "if x is not None" to guard against a None value

[case testUnionMethodCalls]
from typing import Union

Expand Down