Skip to content

Commit

Permalink
Minor fixes of messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eladshoshani committed Apr 23, 2024
1 parent 75107f2 commit 7c9afad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,8 +3413,8 @@ def check_final(self, s: AssignmentStmt | OperatorAssignmentStmt | AssignmentExp
if (
lv.node.final_unset_in_class
and not lv.node.final_set_in_init
and not self.is_stub # It is OK to skip initializer in stub files.
and
and not self.is_stub
and # It is OK to skip initializer in stub files.
# Avoid extra error messages, if there is no type in Final[...],
# then we already reported the error about missing r.h.s.
isinstance(s, AssignmentStmt)
Expand Down
28 changes: 14 additions & 14 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,39 @@ def refine_types(a: Optional[int], b: Optional[str], c: Optional[float]) -> str:
if None in [a, b, c]:
return "One or more are None"
else:
reveal_type(a) # N: Revealed type is 'builtins.int'
reveal_type(b) # N: Revealed type is 'builtins.str'
reveal_type(c) # N: Revealed type is 'builtins.float'
reveal_type(a) # N: Revealed type is "builtins.int"
reveal_type(b) # N: Revealed type is "builtins.str"
reveal_type(c) # N: Revealed type is "builtins.float"
return f"{a}, {b}, {c}"

a: Optional[int] = 5
b: Optional[str] = "hello"
c: Optional[float] = None

result = refine_types(a, b, c)
reveal_type(result) # N: Revealed type is 'builtins.str'
reveal_type(result) # N: Revealed type is "builtins.str"

[case testRefinementWithComplexCondition]
from typing import Optional, List

def refine_complex(a: Optional[int], b: Optional[float], c: Optional[str]) -> str:
# Test with complex conditions mixed with `None in`
if None not in (a, b, c) and b + 3 != 5.5:
reveal_type(a) # N: Revealed type is 'builtins.int'
reveal_type(b) # N: Revealed type is 'builtins.float'
reveal_type(c) # N: Revealed type is 'builtins.str'
reveal_type(a) # N: Revealed type is "builtins.int"
reveal_type(b) # N: Revealed type is "builtins.float"
reveal_type(c) # N: Revealed type is "builtins.str"
return f"{a}, {b}, {c}"
reveal_type(a) # N: Revealed type is 'Union[builtins.int, None]'
reveal_type(b) # N: Revealed type is 'Union[builtins.float, None]'
reveal_type(c) # N: Revealed type is 'Union[builtins.str, None]'
reveal_type(a) # N: Revealed type is "Union[builtins.int, None]"
reveal_type(b) # N: Revealed type is "Union[builtins.float, None]"
reveal_type(c) # N: Revealed type is "Union[builtins.str, None]"
return "All are valid"

a: Optional[int] = 5
b: Optional[float] = 10.3
c: Optional[str] = "cCCCc"

result_complex = refine_complex(a, b, c)
reveal_type(result_complex) # N: Revealed type is 'builtins.str'
reveal_type(result_complex) # N: Revealed type is "builtins.str"

[case testRefinementFailureWhenNonePresent]
from typing import Optional, List
Expand All @@ -153,9 +153,9 @@ def check_failure(a: Optional[int], b: Optional[float], c: Optional[str]) -> str
def not_refine_none_in_iterable(a: Optional[int], b: Optional[float], c: Optional[str]) -> str:
# Test with complex conditions mixed with `None in`
if None not in {a, b, c, None} and b + 3 != 5.5: # E: Unsupported operand types for + ("None" and "int")
reveal_type(a) # N: Revealed type is 'Union[builtins.int, None]'
reveal_type(b) # N: Revealed type is 'Union[builtins.float, None]'
reveal_type(c) # N: Revealed type is 'Union[builtins.str, None]'
reveal_type(a) # N: Revealed type is "Union[builtins.int, None]"
reveal_type(b) # N: Revealed type is "Union[builtins.float, None]"
reveal_type(c) # N: Revealed type is "Union[builtins.str, None]"
return "Bla Bla"

[case testOrCases]
Expand Down

0 comments on commit 7c9afad

Please sign in to comment.