From f434e24252168e3e7ddcb0c6b93639a29c9d7506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 2 May 2019 21:18:20 +0300 Subject: [PATCH] Upgrade mypy (#23586) * Upgrade mypy to 0.701 * Enable strict equality checks * Strict equality error fixes * StateMachine.is_state docstring fix --- homeassistant/core.py | 6 +++--- homeassistant/util/color.py | 6 +++--- homeassistant/util/location.py | 2 +- mypy.ini | 1 + requirements_test.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index df315ad63c0..6dd713e9f0b 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -828,8 +828,8 @@ class StateMachine: """ return self._states.get(entity_id.lower()) - def is_state(self, entity_id: str, state: State) -> bool: - """Test if entity exists and is specified state. + def is_state(self, entity_id: str, state: str) -> bool: + """Test if entity exists and is in specified state. Async friendly. """ @@ -907,7 +907,7 @@ class StateMachine: else: same_state = (old_state.state == new_state and not force_update) - same_attr = old_state.attributes == attributes + same_attr = old_state.attributes == MappingProxyType(attributes) last_changed = old_state.last_changed if same_state else None if same_state and same_attr: diff --git a/homeassistant/util/color.py b/homeassistant/util/color.py index 6d7f3336566..3de6c880f78 100644 --- a/homeassistant/util/color.py +++ b/homeassistant/util/color.py @@ -266,12 +266,12 @@ def color_xy_brightness_to_RGB( vY = xy_closest[1] brightness = ibrightness / 255. - if brightness == 0: + if brightness == 0.0: return (0, 0, 0) Y = brightness - if vY == 0: + if vY == 0.0: vY += 0.00000000001 X = (Y / vY) * vX @@ -304,7 +304,7 @@ def color_xy_brightness_to_RGB( def color_hsb_to_RGB(fH: float, fS: float, fB: float) -> Tuple[int, int, int]: """Convert a hsb into its rgb representation.""" - if fS == 0: + if fS == 0.0: fV = int(fB * 255) return fV, fV, fV diff --git a/homeassistant/util/location.py b/homeassistant/util/location.py index d369bd89098..862391be5e2 100644 --- a/homeassistant/util/location.py +++ b/homeassistant/util/location.py @@ -117,7 +117,7 @@ def vincenty(point1: Tuple[float, float], point2: Tuple[float, float], cosLambda = math.cos(Lambda) sinSigma = math.sqrt((cosU2 * sinLambda) ** 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) ** 2) - if sinSigma == 0: + if sinSigma == 0.0: return 0.0 # coincident points cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda sigma = math.atan2(sinSigma, cosSigma) diff --git a/mypy.ini b/mypy.ini index 1ffdaa0e509..ee893476eed 100644 --- a/mypy.ini +++ b/mypy.ini @@ -4,6 +4,7 @@ disallow_untyped_calls = true follow_imports = silent ignore_missing_imports = true no_implicit_optional = true +strict_equality = true warn_incomplete_stub = true warn_redundant_casts = true warn_return_any = true diff --git a/requirements_test.txt b/requirements_test.txt index 4afcefa4c42..ff4d86436bb 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -7,7 +7,7 @@ coveralls==1.2.0 flake8-docstrings==1.3.0 flake8==3.7.7 mock-open==1.3.1 -mypy==0.670 +mypy==0.701 pydocstyle==3.0.0 pylint==2.3.1 pytest-aiohttp==0.3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 81d24ebdbf4..5f3afebdf6a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -8,7 +8,7 @@ coveralls==1.2.0 flake8-docstrings==1.3.0 flake8==3.7.7 mock-open==1.3.1 -mypy==0.670 +mypy==0.701 pydocstyle==3.0.0 pylint==2.3.1 pytest-aiohttp==0.3.0