From f8b6629b2650d78daad45f2482f51288edd869c4 Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:42:22 +0200 Subject: [PATCH] Enable Ruff PGH rules (#115091) --- pyproject.toml | 2 +- tests/components/knx/conftest.py | 2 +- tests/components/plex/test_update.py | 2 +- tests/components/recorder/db_schema_0.py | 6 ++--- tests/components/recorder/db_schema_16.py | 24 ++++++++--------- tests/components/recorder/db_schema_18.py | 20 +++++++------- tests/components/recorder/db_schema_22.py | 26 +++++++++---------- tests/components/recorder/db_schema_23.py | 26 +++++++++---------- .../db_schema_23_with_newer_columns.py | 26 +++++++++---------- tests/components/ring/test_button.py | 2 +- tests/components/smartthings/test_cover.py | 6 ++--- tests/components/smartthings/test_scene.py | 2 +- tests/util/test_logging.py | 2 +- 13 files changed, 73 insertions(+), 73 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index eb13aa02f5e..f6c7acb0a97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -634,7 +634,7 @@ select = [ "N805", # First argument of a method should be named self "N815", # Variable {name} in class scope should not be mixedCase "PERF", # Perflint - "PGH004", # Use specific rule codes when using noqa + "PGH", # pygrep-hooks "PIE", # flake8-pie "PL", # pylint "PT", # flake8-pytest-style diff --git a/tests/components/knx/conftest.py b/tests/components/knx/conftest.py index 92a9e3594ee..a580fc9eb2c 100644 --- a/tests/components/knx/conftest.py +++ b/tests/components/knx/conftest.py @@ -162,7 +162,7 @@ class KNXTestKit: if payload is not None: assert ( - telegram.payload.value.value == payload # type: ignore + telegram.payload.value.value == payload # type: ignore[attr-defined] ), f"Payload mismatch in {telegram} - Expected: {payload}" async def assert_read(self, group_address: str) -> None: diff --git a/tests/components/plex/test_update.py b/tests/components/plex/test_update.py index a96e0409bbb..942162665af 100644 --- a/tests/components/plex/test_update.py +++ b/tests/components/plex/test_update.py @@ -97,7 +97,7 @@ async def test_plex_update( }, blocking=True, ) - assert apply_mock.called_once + assert apply_mock.call_count == 1 # Failed upgrade request requests_mock.put("/updater/apply", status_code=500) diff --git a/tests/components/recorder/db_schema_0.py b/tests/components/recorder/db_schema_0.py index 6365ff6a7e7..9062de01b59 100644 --- a/tests/components/recorder/db_schema_0.py +++ b/tests/components/recorder/db_schema_0.py @@ -30,7 +30,7 @@ Base = declarative_base() _LOGGER = logging.getLogger(__name__) -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __tablename__ = "events" @@ -66,7 +66,7 @@ class Events(Base): # type: ignore return None -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __tablename__ = "states" @@ -125,7 +125,7 @@ class States(Base): # type: ignore return None -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __tablename__ = "recorder_runs" diff --git a/tests/components/recorder/db_schema_16.py b/tests/components/recorder/db_schema_16.py index 4d48400e370..24786b1ad44 100644 --- a/tests/components/recorder/db_schema_16.py +++ b/tests/components/recorder/db_schema_16.py @@ -66,7 +66,7 @@ DATETIME_TYPE = DateTime(timezone=True).with_variant( ) -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __table_args__ = { @@ -84,7 +84,7 @@ class Events(Base): # type: ignore context_user_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True) context_parent_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True) - __table_args__ = ( # noqa: PIE794 + __table_args__ = ( # type: ignore[assignment] # noqa: PIE794 # Used for fetching events at a specific time # see logbook Index("ix_events_event_type_time_fired", "event_type", "time_fired"), @@ -133,7 +133,7 @@ class Events(Base): # type: ignore return None -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __table_args__ = { @@ -156,7 +156,7 @@ class States(Base): # type: ignore event = relationship("Events", uselist=False) old_state = relationship("States", remote_side=[state_id]) - __table_args__ = ( # noqa: PIE794 + __table_args__ = ( # type: ignore[assignment] # noqa: PIE794 # Used for fetching the state of entities at a specific time # (get_states in history.py) Index("ix_states_entity_id_last_updated", "entity_id", "last_updated"), @@ -217,7 +217,7 @@ class States(Base): # type: ignore return None -class Statistics(Base): # type: ignore +class Statistics(Base): # type: ignore[valid-type,misc] """Statistics.""" __table_args__ = { @@ -237,7 +237,7 @@ class Statistics(Base): # type: ignore state = Column(Float()) sum = Column(Float()) - __table_args__ = ( # noqa: PIE794 + __table_args__ = ( # type: ignore[assignment] # noqa: PIE794 # Used for fetching statistics for a certain entity at a specific time Index("ix_statistics_statistic_id_start", "statistic_id", "start"), ) @@ -253,7 +253,7 @@ class Statistics(Base): # type: ignore ) -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __tablename__ = TABLE_RECORDER_RUNS @@ -304,7 +304,7 @@ class RecorderRuns(Base): # type: ignore return self -class SchemaChanges(Base): # type: ignore +class SchemaChanges(Base): # type: ignore[valid-type,misc] """Representation of schema version changes.""" __tablename__ = TABLE_SCHEMA_CHANGES @@ -366,7 +366,7 @@ class LazyState(State): self._last_updated = None self._context = None - @property # type: ignore + @property def attributes(self): """State attributes.""" if not self._attributes: @@ -383,7 +383,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore + @property def context(self): """State context.""" if not self._context: @@ -395,7 +395,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore + @property def last_changed(self): """Last changed datetime.""" if not self._last_changed: @@ -407,7 +407,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore + @property def last_updated(self): """Last updated datetime.""" if not self._last_updated: diff --git a/tests/components/recorder/db_schema_18.py b/tests/components/recorder/db_schema_18.py index 2ce0dfae5f5..db6fbb78f56 100644 --- a/tests/components/recorder/db_schema_18.py +++ b/tests/components/recorder/db_schema_18.py @@ -68,7 +68,7 @@ DATETIME_TYPE = DateTime(timezone=True).with_variant( ) -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __table_args__ = ( @@ -131,7 +131,7 @@ class Events(Base): # type: ignore return None -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __table_args__ = ( @@ -211,7 +211,7 @@ class States(Base): # type: ignore return None -class Statistics(Base): # type: ignore +class Statistics(Base): # type: ignore[valid-type,misc] """Statistics.""" __table_args__ = ( @@ -244,7 +244,7 @@ class Statistics(Base): # type: ignore ) -class StatisticsMeta(Base): # type: ignore +class StatisticsMeta(Base): # type: ignore[valid-type,misc] """Statistics meta data.""" __tablename__ = TABLE_STATISTICS_META @@ -267,7 +267,7 @@ class StatisticsMeta(Base): # type: ignore ) -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),) @@ -317,7 +317,7 @@ class RecorderRuns(Base): # type: ignore return self -class SchemaChanges(Base): # type: ignore +class SchemaChanges(Base): # type: ignore[valid-type,misc] """Representation of schema version changes.""" __tablename__ = TABLE_SCHEMA_CHANGES @@ -379,7 +379,7 @@ class LazyState(State): self._last_updated = None self._context = None - @property # type: ignore + @property def attributes(self): """State attributes.""" if not self._attributes: @@ -396,7 +396,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore + @property def context(self): """State context.""" if not self._context: @@ -408,7 +408,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore + @property def last_changed(self): """Last changed datetime.""" if not self._last_changed: @@ -420,7 +420,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore + @property def last_updated(self): """Last updated datetime.""" if not self._last_updated: diff --git a/tests/components/recorder/db_schema_22.py b/tests/components/recorder/db_schema_22.py index 0d336c96403..cd0dc52a927 100644 --- a/tests/components/recorder/db_schema_22.py +++ b/tests/components/recorder/db_schema_22.py @@ -84,7 +84,7 @@ DOUBLE_TYPE = ( ) -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __table_args__ = ( @@ -148,7 +148,7 @@ class Events(Base): # type: ignore return None -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __table_args__ = ( @@ -283,13 +283,13 @@ class StatisticsBase: @classmethod def from_stats(cls, metadata_id: int, stats: StatisticData): """Create object from a statistics.""" - return cls( # type: ignore + return cls( # type: ignore[call-arg,misc] metadata_id=metadata_id, **stats, ) -class Statistics(Base, StatisticsBase): # type: ignore +class Statistics(Base, StatisticsBase): # type: ignore[valid-type,misc] """Long term statistics.""" duration = timedelta(hours=1) @@ -301,7 +301,7 @@ class Statistics(Base, StatisticsBase): # type: ignore __tablename__ = TABLE_STATISTICS -class StatisticsShortTerm(Base, StatisticsBase): # type: ignore +class StatisticsShortTerm(Base, StatisticsBase): # type: ignore[valid-type,misc] """Short term statistics.""" duration = timedelta(minutes=5) @@ -322,7 +322,7 @@ class StatisticMetaData(TypedDict): has_sum: bool -class StatisticsMeta(Base): # type: ignore +class StatisticsMeta(Base): # type: ignore[valid-type,misc] """Statistics meta data.""" __table_args__ = ( @@ -354,7 +354,7 @@ class StatisticsMeta(Base): # type: ignore ) -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),) @@ -404,7 +404,7 @@ class RecorderRuns(Base): # type: ignore return self -class SchemaChanges(Base): # type: ignore +class SchemaChanges(Base): # type: ignore[valid-type,misc] """Representation of schema version changes.""" __tablename__ = TABLE_SCHEMA_CHANGES @@ -422,7 +422,7 @@ class SchemaChanges(Base): # type: ignore ) -class StatisticsRuns(Base): # type: ignore +class StatisticsRuns(Base): # type: ignore[valid-type,misc] """Representation of statistics run.""" __tablename__ = TABLE_STATISTICS_RUNS @@ -498,7 +498,7 @@ class LazyState(State): self._last_updated = None self._context = None - @property # type: ignore + @property def attributes(self): """State attributes.""" if not self._attributes: @@ -515,7 +515,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore + @property def context(self): """State context.""" if not self._context: @@ -527,7 +527,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore + @property def last_changed(self): """Last changed datetime.""" if not self._last_changed: @@ -539,7 +539,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore + @property def last_updated(self): """Last updated datetime.""" if not self._last_updated: diff --git a/tests/components/recorder/db_schema_23.py b/tests/components/recorder/db_schema_23.py index d4b6e8b0a73..9187d271216 100644 --- a/tests/components/recorder/db_schema_23.py +++ b/tests/components/recorder/db_schema_23.py @@ -83,7 +83,7 @@ DOUBLE_TYPE = ( ) -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __table_args__ = ( @@ -147,7 +147,7 @@ class Events(Base): # type: ignore return None -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __table_args__ = ( @@ -282,13 +282,13 @@ class StatisticsBase: @classmethod def from_stats(cls, metadata_id: int, stats: StatisticData): """Create object from a statistics.""" - return cls( # type: ignore + return cls( # type: ignore[call-arg,misc] metadata_id=metadata_id, **stats, ) -class Statistics(Base, StatisticsBase): # type: ignore +class Statistics(Base, StatisticsBase): # type: ignore[valid-type,misc] """Long term statistics.""" duration = timedelta(hours=1) @@ -300,7 +300,7 @@ class Statistics(Base, StatisticsBase): # type: ignore __tablename__ = TABLE_STATISTICS -class StatisticsShortTerm(Base, StatisticsBase): # type: ignore +class StatisticsShortTerm(Base, StatisticsBase): # type: ignore[valid-type,misc] """Short term statistics.""" duration = timedelta(minutes=5) @@ -323,7 +323,7 @@ class StatisticMetaData(TypedDict): unit_of_measurement: str | None -class StatisticsMeta(Base): # type: ignore +class StatisticsMeta(Base): # type: ignore[valid-type,misc] """Statistics meta data.""" __table_args__ = ( @@ -344,7 +344,7 @@ class StatisticsMeta(Base): # type: ignore return StatisticsMeta(**meta) -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),) @@ -394,7 +394,7 @@ class RecorderRuns(Base): # type: ignore return self -class SchemaChanges(Base): # type: ignore +class SchemaChanges(Base): # type: ignore[valid-type,misc] """Representation of schema version changes.""" __tablename__ = TABLE_SCHEMA_CHANGES @@ -412,7 +412,7 @@ class SchemaChanges(Base): # type: ignore ) -class StatisticsRuns(Base): # type: ignore +class StatisticsRuns(Base): # type: ignore[valid-type,misc] """Representation of statistics run.""" __tablename__ = TABLE_STATISTICS_RUNS @@ -488,7 +488,7 @@ class LazyState(State): self._last_updated = None self._context = None - @property # type: ignore + @property def attributes(self): """State attributes.""" if not self._attributes: @@ -505,7 +505,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore + @property def context(self): """State context.""" if not self._context: @@ -517,7 +517,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore + @property def last_changed(self): """Last changed datetime.""" if not self._last_changed: @@ -529,7 +529,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore + @property def last_updated(self): """Last updated datetime.""" if not self._last_updated: diff --git a/tests/components/recorder/db_schema_23_with_newer_columns.py b/tests/components/recorder/db_schema_23_with_newer_columns.py index 6893a7257f4..9f902523c64 100644 --- a/tests/components/recorder/db_schema_23_with_newer_columns.py +++ b/tests/components/recorder/db_schema_23_with_newer_columns.py @@ -102,7 +102,7 @@ EVENTS_CONTEXT_ID_BIN_INDEX = "ix_events_context_id_bin" STATES_CONTEXT_ID_BIN_INDEX = "ix_states_context_id_bin" -class Events(Base): # type: ignore +class Events(Base): # type: ignore[valid-type,misc] """Event history data.""" __table_args__ = ( @@ -225,7 +225,7 @@ class EventTypes(Base): # type: ignore[misc,valid-type] event_type = Column(String(MAX_LENGTH_EVENT_EVENT_TYPE)) -class States(Base): # type: ignore +class States(Base): # type: ignore[valid-type,misc] """State change history.""" __table_args__ = ( @@ -406,13 +406,13 @@ class StatisticsBase: @classmethod def from_stats(cls, metadata_id: int, stats: StatisticData): """Create object from a statistics.""" - return cls( # type: ignore + return cls( # type: ignore[call-arg,misc] metadata_id=metadata_id, **stats, ) -class Statistics(Base, StatisticsBase): # type: ignore +class Statistics(Base, StatisticsBase): # type: ignore[valid-type,misc] """Long term statistics.""" duration = timedelta(hours=1) @@ -424,7 +424,7 @@ class Statistics(Base, StatisticsBase): # type: ignore __tablename__ = TABLE_STATISTICS -class StatisticsShortTerm(Base, StatisticsBase): # type: ignore +class StatisticsShortTerm(Base, StatisticsBase): # type: ignore[valid-type,misc] """Short term statistics.""" duration = timedelta(minutes=5) @@ -447,7 +447,7 @@ class StatisticMetaData(TypedDict): unit_of_measurement: str | None -class StatisticsMeta(Base): # type: ignore +class StatisticsMeta(Base): # type: ignore[valid-type,misc] """Statistics meta data.""" __table_args__ = ( @@ -468,7 +468,7 @@ class StatisticsMeta(Base): # type: ignore return StatisticsMeta(**meta) -class RecorderRuns(Base): # type: ignore +class RecorderRuns(Base): # type: ignore[valid-type,misc] """Representation of recorder run.""" __table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),) @@ -518,7 +518,7 @@ class RecorderRuns(Base): # type: ignore return self -class SchemaChanges(Base): # type: ignore +class SchemaChanges(Base): # type: ignore[valid-type,misc] """Representation of schema version changes.""" __tablename__ = TABLE_SCHEMA_CHANGES @@ -536,7 +536,7 @@ class SchemaChanges(Base): # type: ignore ) -class StatisticsRuns(Base): # type: ignore +class StatisticsRuns(Base): # type: ignore[valid-type,misc] """Representation of statistics run.""" __tablename__ = TABLE_STATISTICS_RUNS @@ -612,7 +612,7 @@ class LazyState(State): self._last_updated = None self._context = None - @property # type: ignore + @property def attributes(self): """State attributes.""" if not self._attributes: @@ -629,7 +629,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore + @property def context(self): """State context.""" if not self._context: @@ -641,7 +641,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore + @property def last_changed(self): """Last changed datetime.""" if not self._last_changed: @@ -653,7 +653,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore + @property def last_updated(self): """Last updated datetime.""" if not self._last_updated: diff --git a/tests/components/ring/test_button.py b/tests/components/ring/test_button.py index 6f0c29b1fcc..6b2200b2bf3 100644 --- a/tests/components/ring/test_button.py +++ b/tests/components/ring/test_button.py @@ -39,4 +39,4 @@ async def test_button_opens_door( ) await hass.async_block_till_done() - assert mock.called_once + assert mock.call_count == 1 diff --git a/tests/components/smartthings/test_cover.py b/tests/components/smartthings/test_cover.py index c4f6c15a3fe..e19ac403e5d 100644 --- a/tests/components/smartthings/test_cover.py +++ b/tests/components/smartthings/test_cover.py @@ -140,7 +140,7 @@ async def test_set_cover_position_switch_level( assert state.attributes[ATTR_CURRENT_POSITION] == 10 # Ensure API called - assert device._api.post_device_command.call_count == 1 # type: ignore + assert device._api.post_device_command.call_count == 1 async def test_set_cover_position(hass: HomeAssistant, device_factory) -> None: @@ -171,7 +171,7 @@ async def test_set_cover_position(hass: HomeAssistant, device_factory) -> None: assert state.attributes[ATTR_CURRENT_POSITION] == 10 # Ensure API called - assert device._api.post_device_command.call_count == 1 # type: ignore + assert device._api.post_device_command.call_count == 1 async def test_set_cover_position_unsupported( @@ -196,7 +196,7 @@ async def test_set_cover_position_unsupported( # Ensure API was not called - assert device._api.post_device_command.call_count == 0 # type: ignore + assert device._api.post_device_command.call_count == 0 async def test_update_to_open_from_signal(hass: HomeAssistant, device_factory) -> None: diff --git a/tests/components/smartthings/test_scene.py b/tests/components/smartthings/test_scene.py index 1eaaad55d0f..d33db0a1dd9 100644 --- a/tests/components/smartthings/test_scene.py +++ b/tests/components/smartthings/test_scene.py @@ -38,7 +38,7 @@ async def test_scene_activate(hass: HomeAssistant, scene) -> None: assert state.attributes["icon"] == scene.icon assert state.attributes["color"] == scene.color assert state.attributes["location_id"] == scene.location_id - assert scene.execute.call_count == 1 # type: ignore + assert scene.execute.call_count == 1 async def test_unload_config_entry(hass: HomeAssistant, scene) -> None: diff --git a/tests/util/test_logging.py b/tests/util/test_logging.py index 53342e8d1bd..8e7106475a2 100644 --- a/tests/util/test_logging.py +++ b/tests/util/test_logging.py @@ -20,7 +20,7 @@ import homeassistant.util.logging as logging_util async def test_logging_with_queue_handler() -> None: """Test logging with HomeAssistantQueueHandler.""" - simple_queue = queue.SimpleQueue() # type: ignore + simple_queue = queue.SimpleQueue() handler = logging_util.HomeAssistantQueueHandler(simple_queue) log_record = logging.makeLogRecord({"msg": "Test Log Record"})