8000 Make operations on None fall back on object by ddfisher · Pull Request #1835 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Make operations on None fall back on object #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2016
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
13 changes: 11 additions & 2 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
from mypy import subtypes


def analyze_member_access(name: str, typ: Type, node: Context, is_lvalue: bool,
def analyze_member_access(name: str,
typ: Type,
node: Context,
is_lvalue: bool,
is_super: bool,
builtin_type: Callable[[str], Instance],
not_ready_callback: Callable[[str, Context], None],
msg: MessageBuilder, override_info: TypeInfo = None,
msg: MessageBuilder,
override_info: TypeInfo = None,
report_type: Type = None) -> Type:
"""Analyse attribute access.

Expand Down Expand Up @@ -72,6 +76,11 @@ def analyze_member_access(name: str, typ: Type, node: Context, is_lvalue: bool,
elif isinstance(typ, AnyType):
# The base object has dynamic type.
return AnyType()
elif isinstance(typ, NoneTyp):
# The only attribute NoneType has are those it inherits from object
return analyze_member_access(name, builtin_type('builtins.object'), node, is_lvalue,
is_super, builtin_type, not_ready_callback, msg,
report_type=report_type)
elif isinstance(typ, UnionType):
995F # The base object has dynamic type.
msg.disable_type_names += 1
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1493,3 +1493,11 @@ reveal_type("foo") # E: Argument 1 to "reveal_type" has incompatible type "str";
[case testRevealTypeVar]
reveal_type = 1
1 + "foo" # E: Unsupported operand types for + ("int" and "str")

[case testEqNone]
None == None
[builtins fixtures/ops.py]

[case testLtNone]
None < None # E: Unsupported left operand type for < (None)
[builtins fixtures/ops.py]
0