Skip to content

Commit 10ea6ad

Browse files
committed
Merge branch 'master' into better-incompatible-messages
2 parents f01efec + 8853f22 commit 10ea6ad

File tree

7 files changed

+134
-141
lines changed

7 files changed

+134
-141
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5096,7 +5096,7 @@ def gen_unique_name(base: str, table: SymbolTable) -> str:
50965096
def is_true_literal(n: Expression) -> bool:
50975097
"""Returns true if this expression is the 'True' literal/keyword."""
50985098
return (refers_to_fullname(n, 'builtins.True')
5099-
or isinstance(n, IntExpr) and n.value == 1)
5099+
or isinstance(n, IntExpr) and n.value != 0)
51005100

51015101

51025102
def is_false_literal(n: Expression) -> bool:

mypy/state.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ def strict_optional_set(value: bool) -> Iterator[None]:
1414
global strict_optional
1515
saved = strict_optional
1616
strict_optional = value
17-
yield
18-
strict_optional = saved
17+
try:
18+
yield
19+
finally:
20+
strict_optional = saved

mypy/test/helpers.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shutil
66
import contextlib
77

8-
from typing import List, Iterable, Dict, Tuple, Callable, Any, Optional, Iterator
8+
from typing import List, Iterable, Dict, Tuple, Callable, Any, Iterator
99

1010
from mypy import defaults
1111
import mypy.api as api
@@ -50,6 +50,7 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str],
5050
5151
Display any differences in a human-readable form.
5252
"""
53+
__tracebackhide__ = True
5354

5455
actual = clean_up(actual)
5556
actual = [line.replace("can't", "cannot") for line in actual]
@@ -326,18 +327,6 @@ def retry_on_error(func: Callable[[], Any], max_wait: float = 1.0) -> None:
326327
raise
327328
time.sleep(wait_time)
328329

329-
# TODO: assert_true and assert_false are redundant - use plain assert
330-
331-
332-
def assert_true(b: bool, msg: Optional[str] = None) -> None:
333-
if not b:
334-
raise AssertionError(msg)
335-
336-
337-
def assert_false(b: bool, msg: Optional[str] = None) -> None:
338-
if b:
339-
raise AssertionError(msg)
340-
341330

342331
def good_repr(obj: object) -> str:
343332
if isinstance(obj, str):
@@ -352,6 +341,7 @@ def good_repr(obj: object) -> str:
352341

353342

354343
def assert_equal(a: object, b: object, fmt: str = '{} != {}') -> None:
344+
__tracebackhide__ = True
355345
if a != b:
356346
raise AssertionError(fmt.format(good_repr(a), good_repr(b)))
357347

@@ -364,6 +354,7 @@ def typename(t: type) -> str:
364354

365355

366356
def assert_type(typ: type, value: object) -> None:
357+
__tracebackhide__ = True
367358
if type(value) != typ:
368359
raise AssertionError('Invalid type {}, expected {}'.format(
369360
typename(type(value)), typename(typ)))

mypy/test/testsubtypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from mypy.test.helpers import Suite, assert_true, skip
1+
from mypy.test.helpers import Suite, skip
22
from mypy.nodes import CONTRAVARIANT, INVARIANT, COVARIANT
33
from mypy.subtypes import is_subtype
44
from mypy.test.typefixture import TypeFixture, InterfaceTypeFixture
@@ -188,10 +188,10 @@ def test_type_callable_subtyping(self) -> None:
188188
# * generic function types
189189

190190
def assert_subtype(self, s: Type, t: Type) -> None:
191-
assert_true(is_subtype(s, t), '{} not subtype of {}'.format(s, t))
191+
assert is_subtype(s, t), '{} not subtype of {}'.format(s, t)
192192

193193
def assert_not_subtype(self, s: Type, t: Type) -> None:
194-
assert_true(not is_subtype(s, t), '{} subtype of {}'.format(s, t))
194+
assert not is_subtype(s, t), '{} subtype of {}'.format(s, t)
195195

196196
def assert_strict_subtype(self, s: Type, t: Type) -> None:
197197
self.assert_subtype(s, t)

0 commit comments

Comments
 (0)