Bump lru-dict to 1.3.0 (#105914)

* Bump lru-dict to 1.3.0

changelog: https://github.com/amitdev/lru-dict/compare/v1.2.0...v1.3.0

* fix typing

* quote types

* quote types
This commit is contained in:
J. Nick Koston 2023-12-17 13:16:31 -10:00 committed by GitHub
parent 45b5ddfad7
commit 5c503683b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 26 additions and 34 deletions

View File

@ -7,7 +7,7 @@ from functools import lru_cache
import re
from typing import TYPE_CHECKING, Final, Generic, TypedDict, TypeVar
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
from homeassistant.core import callback
from homeassistant.loader import BluetoothMatcher, BluetoothMatcherOptional
@ -15,8 +15,6 @@ from homeassistant.loader import BluetoothMatcher, BluetoothMatcherOptional
from .models import BluetoothCallback, BluetoothServiceInfoBleak
if TYPE_CHECKING:
from collections.abc import MutableMapping
from bleak.backends.scanner import AdvertisementData
@ -97,10 +95,8 @@ class IntegrationMatcher:
self._integration_matchers = integration_matchers
# Some devices use a random address so we need to use
# an LRU to avoid memory issues.
self._matched: MutableMapping[str, IntegrationMatchHistory] = LRU(
MAX_REMEMBER_ADDRESSES
)
self._matched_connectable: MutableMapping[str, IntegrationMatchHistory] = LRU(
self._matched: LRU[str, IntegrationMatchHistory] = LRU(MAX_REMEMBER_ADDRESSES)
self._matched_connectable: LRU[str, IntegrationMatchHistory] = LRU(
MAX_REMEMBER_ADDRESSES
)
self._index = BluetoothMatcherIndex()

View File

@ -1,7 +1,7 @@
"""Static file handling for HTTP component."""
from __future__ import annotations
from collections.abc import Mapping, MutableMapping
from collections.abc import Mapping
import mimetypes
from pathlib import Path
from typing import Final
@ -10,7 +10,7 @@ from aiohttp import hdrs
from aiohttp.web import FileResponse, Request, StreamResponse
from aiohttp.web_exceptions import HTTPForbidden, HTTPNotFound
from aiohttp.web_urldispatcher import StaticResource
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
from homeassistant.core import HomeAssistant
@ -19,9 +19,7 @@ from .const import KEY_HASS
CACHE_TIME: Final = 31 * 86400 # = 1 month
CACHE_HEADER = f"public, max-age={CACHE_TIME}"
CACHE_HEADERS: Mapping[str, str] = {hdrs.CACHE_CONTROL: CACHE_HEADER}
PATH_CACHE: MutableMapping[
tuple[str, Path, bool], tuple[Path | None, str | None]
] = LRU(512)
PATH_CACHE: LRU[tuple[str, Path, bool], tuple[Path | None, str | None]] = LRU(512)
def _get_file_path(rel_url: str, directory: Path, follow_symlinks: bool) -> Path | None:

View File

@ -11,7 +11,7 @@ import time
import traceback
from typing import Any, cast
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
import voluptuous as vol
from homeassistant.components import persistent_notification

View File

@ -1,9 +1,8 @@
"""Managers for each table."""
from collections.abc import MutableMapping
from typing import TYPE_CHECKING, Generic, TypeVar
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
if TYPE_CHECKING:
from ..core import Recorder
@ -14,6 +13,8 @@ _DataT = TypeVar("_DataT")
class BaseTableManager(Generic[_DataT]):
"""Base class for table managers."""
_id_map: "LRU[str, int]"
def __init__(self, recorder: "Recorder") -> None:
"""Initialize the table manager.
@ -24,7 +25,6 @@ class BaseTableManager(Generic[_DataT]):
self.active = False
self.recorder = recorder
self._pending: dict[str, _DataT] = {}
self._id_map: MutableMapping[str, int] = {}
def get_from_cache(self, data: str) -> int | None:
"""Resolve data to the id without accessing the underlying database.
@ -62,7 +62,7 @@ class BaseLRUTableManager(BaseTableManager[_DataT]):
and evict the least recently used items when the cache is full.
"""
super().__init__(recorder)
self._id_map: MutableMapping[str, int] = LRU(lru_size)
self._id_map = LRU(lru_size)
def adjust_lru_size(self, new_size: int) -> None:
"""Adjust the LRU cache size.
@ -70,6 +70,6 @@ class BaseLRUTableManager(BaseTableManager[_DataT]):
This call is not thread-safe and must be called from the
recorder thread.
"""
lru: LRU = self._id_map
lru = self._id_map
if new_size > lru.get_size():
lru.set_size(new_size)

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Iterable
from typing import TYPE_CHECKING, cast
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
from sqlalchemy.orm.session import Session
from homeassistant.core import Event
@ -28,7 +28,7 @@ class EventTypeManager(BaseLRUTableManager[EventTypes]):
def __init__(self, recorder: Recorder) -> None:
"""Initialize the event type manager."""
super().__init__(recorder, CACHE_SIZE)
self._non_existent_event_types: LRU = LRU(CACHE_SIZE)
self._non_existent_event_types: LRU[str, None] = LRU(CACHE_SIZE)
def load(self, events: list[Event], session: Session) -> None:
"""Load the event_type to event_type_ids mapping into memory.

View File

@ -5,7 +5,7 @@ import logging
import threading
from typing import TYPE_CHECKING, Literal, cast
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
from sqlalchemy import lambda_stmt, select
from sqlalchemy.orm.session import Session
from sqlalchemy.sql.expression import true
@ -74,7 +74,7 @@ class StatisticsMetaManager:
def __init__(self, recorder: Recorder) -> None:
"""Initialize the statistics meta manager."""
self.recorder = recorder
self._stat_id_to_id_meta: dict[str, tuple[int, StatisticMetaData]] = LRU(
self._stat_id_to_id_meta: LRU[str, tuple[int, StatisticMetaData]] = LRU(
CACHE_SIZE
)

View File

@ -5,7 +5,7 @@ from ast import literal_eval
import asyncio
import base64
import collections.abc
from collections.abc import Callable, Collection, Generator, Iterable, MutableMapping
from collections.abc import Callable, Collection, Generator, Iterable
from contextlib import AbstractContextManager, suppress
from contextvars import ContextVar
from datetime import datetime, timedelta
@ -40,7 +40,7 @@ from jinja2 import pass_context, pass_environment, pass_eval_context
from jinja2.runtime import AsyncLoopContext, LoopContext
from jinja2.sandbox import ImmutableSandboxedEnvironment
from jinja2.utils import Namespace
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
import orjson
import voluptuous as vol
@ -147,10 +147,8 @@ EVAL_CACHE_SIZE = 512
MAX_CUSTOM_TEMPLATE_SIZE = 5 * 1024 * 1024
CACHED_TEMPLATE_LRU: MutableMapping[State, TemplateState] = LRU(CACHED_TEMPLATE_STATES)
CACHED_TEMPLATE_NO_COLLECT_LRU: MutableMapping[State, TemplateState] = LRU(
CACHED_TEMPLATE_STATES
)
CACHED_TEMPLATE_LRU: LRU[State, TemplateState] = LRU(CACHED_TEMPLATE_STATES)
CACHED_TEMPLATE_NO_COLLECT_LRU: LRU[State, TemplateState] = LRU(CACHED_TEMPLATE_STATES)
ENTITY_COUNT_GROWTH_FACTOR = 1.2
ORJSON_PASSTHROUGH_OPTIONS = (
@ -187,9 +185,9 @@ def async_setup(hass: HomeAssistant) -> bool:
)
for lru in (CACHED_TEMPLATE_LRU, CACHED_TEMPLATE_NO_COLLECT_LRU):
# There is no typing for LRU
current_size = lru.get_size() # type: ignore[attr-defined]
current_size = lru.get_size()
if new_size > current_size:
lru.set_size(new_size) # type: ignore[attr-defined]
lru.set_size(new_size)
from .event import ( # pylint: disable=import-outside-toplevel
async_track_time_interval,

View File

@ -33,7 +33,7 @@ httpx==0.25.0
ifaddr==0.2.0
janus==1.0.0
Jinja2==3.1.2
lru-dict==1.2.0
lru-dict==1.3.0
mutagen==1.47.0
orjson==3.9.9
packaging>=23.1

View File

@ -40,7 +40,7 @@ dependencies = [
"home-assistant-bluetooth==1.11.0",
"ifaddr==0.2.0",
"Jinja2==3.1.2",
"lru-dict==1.2.0",
"lru-dict==1.3.0",
"PyJWT==2.8.0",
# PyJWT has loose dependency. We want the latest one.
"cryptography==41.0.7",

View File

@ -18,7 +18,7 @@ httpx==0.25.0
home-assistant-bluetooth==1.11.0
ifaddr==0.2.0
Jinja2==3.1.2
lru-dict==1.2.0
lru-dict==1.3.0
PyJWT==2.8.0
cryptography==41.0.7
pyOpenSSL==23.2.0

View File

@ -5,7 +5,7 @@ import os
from pathlib import Path
from unittest.mock import patch
from lru import LRU # pylint: disable=no-name-in-module
from lru import LRU
import pytest
from homeassistant.components.profiler import (