Enable Ruff PGH rules (#115091)

pull/115215/head^2
Sid 2024-04-08 15:42:22 +02:00 committed by GitHub
parent 85b453b86c
commit f8b6629b26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 73 additions and 73 deletions

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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"

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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"})