Skip to content

Commit

Permalink
Add pylint rule for cached_property (home-assistant#127482)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 3, 2024
1 parent 1dd5937 commit 6eb4999
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions homeassistant/backports/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

# pylint: disable-next=hass-deprecated-import
from functools import cached_property as _cached_property, partial

from homeassistant.helpers.deprecation import (
Expand Down
11 changes: 7 additions & 4 deletions pylint/plugins/hass_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class ObsoleteImportMatch:


_OBSOLETE_IMPORT: dict[str, list[ObsoleteImportMatch]] = {
"functools": [
ObsoleteImportMatch(
reason="replaced by propcache.cached_property",
constant=re.compile(r"^cached_property$"),
),
],
"homeassistant.backports.enum": [
ObsoleteImportMatch(
reason="We can now use the Python 3.11 provided enum.StrEnum instead",
Expand All @@ -27,10 +33,7 @@ class ObsoleteImportMatch:
],
"homeassistant.backports.functools": [
ObsoleteImportMatch(
reason=(
"We can now use the Python 3.12 provided "
"functools.cached_property instead"
),
reason="replaced by propcache.cached_property",
constant=re.compile(r"^cached_property$"),
),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from enum import StrEnum
from functools import cached_property
from functools import cached_property # pylint: disable=hass-deprecated-import
from types import ModuleType
from typing import Any

Expand Down

0 comments on commit 6eb4999

Please sign in to comment.