From 0188e8b319b6c82ff4ea9233d609cd2e9e3a2d11 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 18 Feb 2022 11:30:59 +0100 Subject: [PATCH] Add type ignore error codes [util] (#66777) --- homeassistant/util/__init__.py | 4 ++-- homeassistant/util/json.py | 2 +- homeassistant/util/package.py | 2 +- homeassistant/util/unit_system.py | 10 +++++----- homeassistant/util/yaml/dumper.py | 2 +- homeassistant/util/yaml/loader.py | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index 5c2882ec2e2..15e9254e9d8 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -137,7 +137,7 @@ class Throttle: else: - def throttled_value() -> None: # type: ignore + def throttled_value() -> None: # type: ignore[misc] """Stand-in function for when real func is being throttled.""" return None @@ -191,7 +191,7 @@ class Throttle: if force or utcnow() - throttle[1] > self.min_time: result = method(*args, **kwargs) throttle[1] = utcnow() - return result # type: ignore + return result # type: ignore[no-any-return] return throttled_value() finally: diff --git a/homeassistant/util/json.py b/homeassistant/util/json.py index 9c98691c605..fdee7a7a90f 100644 --- a/homeassistant/util/json.py +++ b/homeassistant/util/json.py @@ -30,7 +30,7 @@ def load_json(filename: str, default: list | dict | None = None) -> list | dict: """ try: with open(filename, encoding="utf-8") as fdesc: - return json.loads(fdesc.read()) # type: ignore + return json.loads(fdesc.read()) # type: ignore[no-any-return] except FileNotFoundError: # This is not a fatal error _LOGGER.debug("JSON file not found: %s", filename) diff --git a/homeassistant/util/package.py b/homeassistant/util/package.py index a1ee2b9f584..aad93e37542 100644 --- a/homeassistant/util/package.py +++ b/homeassistant/util/package.py @@ -50,7 +50,7 @@ def is_installed(package: str) -> bool: # was aborted while in progress see # https://github.com/home-assistant/core/issues/47699 if installed_version is None: - _LOGGER.error("Installed version for %s resolved to None", req.project_name) # type: ignore + _LOGGER.error("Installed version for %s resolved to None", req.project_name) # type: ignore[unreachable] return False return installed_version in req except PackageNotFoundError: diff --git a/homeassistant/util/unit_system.py b/homeassistant/util/unit_system.py index dfe73b0e937..e964fee798c 100644 --- a/homeassistant/util/unit_system.py +++ b/homeassistant/util/unit_system.py @@ -134,7 +134,7 @@ class UnitSystem: raise TypeError(f"{length!s} is not a numeric value.") # type ignore: https://github.com/python/mypy/issues/7207 - return distance_util.convert( # type: ignore + return distance_util.convert( # type: ignore[unreachable] length, from_unit, self.length_unit ) @@ -144,7 +144,7 @@ class UnitSystem: raise TypeError(f"{precip!s} is not a numeric value.") # type ignore: https://github.com/python/mypy/issues/7207 - return distance_util.convert( # type: ignore + return distance_util.convert( # type: ignore[unreachable] precip, from_unit, self.accumulated_precipitation_unit ) @@ -154,7 +154,7 @@ class UnitSystem: raise TypeError(f"{pressure!s} is not a numeric value.") # type ignore: https://github.com/python/mypy/issues/7207 - return pressure_util.convert( # type: ignore + return pressure_util.convert( # type: ignore[unreachable] pressure, from_unit, self.pressure_unit ) @@ -164,7 +164,7 @@ class UnitSystem: raise TypeError(f"{wind_speed!s} is not a numeric value.") # type ignore: https://github.com/python/mypy/issues/7207 - return speed_util.convert(wind_speed, from_unit, self.wind_speed_unit) # type: ignore + return speed_util.convert(wind_speed, from_unit, self.wind_speed_unit) # type: ignore[unreachable] def volume(self, volume: float | None, from_unit: str) -> float: """Convert the given volume to this unit system.""" @@ -172,7 +172,7 @@ class UnitSystem: raise TypeError(f"{volume!s} is not a numeric value.") # type ignore: https://github.com/python/mypy/issues/7207 - return volume_util.convert(volume, from_unit, self.volume_unit) # type: ignore + return volume_util.convert(volume, from_unit, self.volume_unit) # type: ignore[unreachable] def as_dict(self) -> dict[str, str]: """Convert the unit system to a dictionary.""" diff --git a/homeassistant/util/yaml/dumper.py b/homeassistant/util/yaml/dumper.py index 8e9cb382b6c..3eafc8abdd7 100644 --- a/homeassistant/util/yaml/dumper.py +++ b/homeassistant/util/yaml/dumper.py @@ -24,7 +24,7 @@ def save_yaml(path: str, data: dict) -> None: # From: https://gist.github.com/miracle2k/3184458 -def represent_odict( # type: ignore +def represent_odict( # type: ignore[no-untyped-def] dumper, tag, mapping, flow_style=None ) -> yaml.MappingNode: """Like BaseRepresenter.represent_mapping but does not issue the sort().""" diff --git a/homeassistant/util/yaml/loader.py b/homeassistant/util/yaml/loader.py index e6ac5fd364a..84349ef91a9 100644 --- a/homeassistant/util/yaml/loader.py +++ b/homeassistant/util/yaml/loader.py @@ -100,7 +100,7 @@ class SafeLineLoader(yaml.SafeLoader): """Annotate a node with the first line it was seen.""" last_line: int = self.line node: yaml.nodes.Node = super().compose_node(parent, index) # type: ignore[assignment] - node.__line__ = last_line + 1 # type: ignore + node.__line__ = last_line + 1 # type: ignore[attr-defined] return node @@ -149,7 +149,7 @@ def _add_reference( ... -def _add_reference(obj, loader: SafeLineLoader, node: yaml.nodes.Node): # type: ignore +def _add_reference(obj, loader: SafeLineLoader, node: yaml.nodes.Node): # type: ignore[no-untyped-def] """Add file reference information to an object.""" if isinstance(obj, list): obj = NodeListClass(obj) -- GitLab