Skip to content
Merged
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 mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,18 @@ def analyze_union_member_access(name: str, typ: UnionType, mx: MemberContext) ->


def analyze_none_member_access(name: str, typ: NoneType, mx: MemberContext) -> Type:
if mx.chk.should_suppress_optional_error([typ]):
return AnyType(TypeOfAny.from_error)
is_python_3 = mx.chk.options.python_version[0] >= 3
# In Python 2 "None" has exactly the same attributes as "object". Python 3 adds a single
# extra attribute, "__bool__".
if is_python_3 and name == '__bool__':
literal_false = LiteralType(False, fallback=mx.named_type('builtins.bool'))
Comment thread
sobolevn marked this conversation as resolved.
return CallableType(arg_types=[],
arg_kinds=[],
arg_names=[],
ret_type=mx.named_type('builtins.bool'),
ret_type=literal_false,
fallback=mx.named_type('builtins.function'))
elif mx.chk.should_suppress_optional_error([typ]):
return AnyType(TypeOfAny.from_error)
else:
return _analyze_member_access(name, mx.named_type('builtins.object'), mx)

Expand Down
11 changes: 10 additions & 1 deletion test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,18 @@ def foo(
[case testNoneHasBool]
none = None
b = none.__bool__()
reveal_type(b) # N: Revealed type is "builtins.bool"
reveal_type(b) # N: Revealed type is "Literal[False]"
[builtins fixtures/bool.pyi]

[case testNoneHasBoolShowNoneErrorsFalse]
none = None
b = none.__bool__()
reveal_type(b) # N: Revealed type is "Literal[False]"
[builtins fixtures/bool.pyi]
[file mypy.ini]
\[mypy]
show_none_errors = False

[case testAssignmentInvariantNoteForList]
from typing import List
x: List[int]
Expand Down