Skip to content

Commit 6f2dcc0

Browse files
committed
Rework mypy options
* Remove --strict-optional (now default) * Add --disallow-untyped-decorators * Add --check-untyped-defs * Fix type warnings in tests
1 parent e60cdb9 commit 6f2dcc0

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

mypy.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[mypy]
2-
ignore_missing_imports = True
32
disallow_subclassing_any = True
3+
disallow_untyped_decorators = True
4+
check_untyped_defs = True
45
warn_redundant_casts = True
56
warn_return_any = True
67
warn_unused_ignores = True
78
warn_unused_configs = True
89
no_implicit_optional = True
9-
strict_optional = True

test_asserts.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242

4343
class _DummyObject(object):
44-
4544
def __init__(self, value="x"):
4645
self.value = value
4746

@@ -253,7 +252,7 @@ def test_assert_almost_equal__not_similar__delta__custom_message(self):
253252

254253
def test_assert_almost_equal__wrong_types(self):
255254
try:
256-
assert_almost_equal("5", "5")
255+
assert_almost_equal("5", "5") # type: ignore
257256
except TypeError:
258257
pass
259258
else:
@@ -336,7 +335,7 @@ def test_assert_not_almost_equal__similar__delta__custom_message(self):
336335

337336
def test_assert_not_almost_equal__wrong_types(self):
338337
try:
339-
assert_not_almost_equal("5", "5")
338+
assert_not_almost_equal("5", "5") # type: ignore
340339
except TypeError:
341340
pass
342341
else:
@@ -643,8 +642,7 @@ def test_assert_not_is_instance__custom_message__multiple_types(self):
643642

644643
def test_assert_has_attr__has_attribute(self):
645644
d = _DummyObject()
646-
d.foo = 5
647-
assert_has_attr(d, "foo")
645+
assert_has_attr(d, "value")
648646

649647
def test_assert_has_attr__does_not_have_attribute__default_message(self):
650648
d = _DummyObject()
@@ -961,20 +959,22 @@ def test_assert_warns__multiple_warnings(self):
961959
warn("baz", FutureWarning)
962960

963961
def test_assert_warns__warning_handler_deinstalled_on_success(self):
964-
with catch_warnings(record=1) as warnings:
962+
with catch_warnings(record=True) as warnings:
965963
with assert_warns(UserWarning):
966964
warn("foo", UserWarning)
965+
assert warnings is not None
967966
assert_equal(0, len(warnings))
968967
warn("bar", UserWarning)
969968
assert_equal(1, len(warnings))
970969

971970
def test_assert_warns__warning_handler_deinstalled_on_failure(self):
972-
with catch_warnings(record=1) as warnings:
971+
with catch_warnings(record=True) as warnings:
973972
try:
974973
with assert_warns(UserWarning):
975974
pass
976975
except AssertionError:
977976
pass
977+
assert warnings is not None
978978
assert_equal(0, len(warnings))
979979
warn("bar", UserWarning)
980980
assert_equal(1, len(warnings))
@@ -1016,20 +1016,22 @@ def test_assert_warns_regex__multiple_warnings(self):
10161016
warn("baz", FutureWarning)
10171017

10181018
def test_assert_warns_regex__warning_handler_deinstalled_on_success(self):
1019-
with catch_warnings(record=1) as warnings:
1019+
with catch_warnings(record=True) as warnings:
10201020
with assert_warns_regex(UserWarning, r"foo"):
10211021
warn("foo", UserWarning)
1022+
assert warnings is not None
10221023
assert_equal(0, len(warnings))
10231024
warn("bar", UserWarning)
10241025
assert_equal(1, len(warnings))
10251026

10261027
def test_assert_warns_regex__warning_handler_deinstalled_on_failure(self):
1027-
with catch_warnings(record=1) as warnings:
1028+
with catch_warnings(record=True) as warnings:
10281029
try:
10291030
with assert_warns_regex(UserWarning, r""):
10301031
pass
10311032
except AssertionError:
10321033
pass
1034+
assert warnings is not None
10331035
assert_equal(0, len(warnings))
10341036
warn("bar", UserWarning)
10351037
assert_equal(1, len(warnings))

0 commit comments

Comments
 (0)