mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Update Python version for mypy to 3.13 (#135636)
This commit is contained in:
parent
c4d8cda92b
commit
239aa94b6f
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Final
|
from typing import Final
|
||||||
|
|
||||||
from aiohttp.hdrs import CACHE_CONTROL, CONTENT_TYPE
|
from aiohttp.hdrs import CACHE_CONTROL, CONTENT_TYPE
|
||||||
from aiohttp.web import FileResponse, Request, StreamResponse
|
from aiohttp.web import FileResponse, Request, StreamResponse
|
||||||
@ -17,12 +17,7 @@ CACHE_HEADER = f"public, max-age={CACHE_TIME}"
|
|||||||
CACHE_HEADERS: Mapping[str, str] = {CACHE_CONTROL: CACHE_HEADER}
|
CACHE_HEADERS: Mapping[str, str] = {CACHE_CONTROL: CACHE_HEADER}
|
||||||
RESPONSE_CACHE: LRU[tuple[str, Path], tuple[Path, str]] = LRU(512)
|
RESPONSE_CACHE: LRU[tuple[str, Path], tuple[Path, str]] = LRU(512)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
_GUESSER = CONTENT_TYPES.guess_file_type
|
||||||
# mypy uses Python 3.12 syntax for type checking
|
|
||||||
# once it uses Python 3.13, this can be removed
|
|
||||||
_GUESSER = CONTENT_TYPES.guess_type
|
|
||||||
else:
|
|
||||||
_GUESSER = CONTENT_TYPES.guess_file_type
|
|
||||||
|
|
||||||
|
|
||||||
class CachingStaticResource(StaticResource):
|
class CachingStaticResource(StaticResource):
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
"""Helpers for config validation using voluptuous."""
|
"""Helpers for config validation using voluptuous."""
|
||||||
|
|
||||||
# PEP 563 seems to break typing.get_type_hints when used
|
from __future__ import annotations
|
||||||
# with PEP 695 syntax. Fixed in Python 3.13.
|
|
||||||
# from __future__ import annotations
|
|
||||||
|
|
||||||
from collections.abc import Callable, Hashable, Mapping
|
from collections.abc import Callable, Hashable, Mapping
|
||||||
import contextlib
|
import contextlib
|
||||||
@ -354,7 +352,7 @@ def ensure_list[_T](value: _T | None) -> list[_T] | list[Any]:
|
|||||||
"""Wrap value in list if it is not one."""
|
"""Wrap value in list if it is not one."""
|
||||||
if value is None:
|
if value is None:
|
||||||
return []
|
return []
|
||||||
return cast("list[_T]", value) if isinstance(value, list) else [value]
|
return cast(list[_T], value) if isinstance(value, list) else [value]
|
||||||
|
|
||||||
|
|
||||||
def entity_id(value: Any) -> str:
|
def entity_id(value: Any) -> str:
|
||||||
|
2
mypy.ini
generated
2
mypy.ini
generated
@ -3,7 +3,7 @@
|
|||||||
# To update, run python3 -m script.hassfest -p mypy_config
|
# To update, run python3 -m script.hassfest -p mypy_config
|
||||||
|
|
||||||
[mypy]
|
[mypy]
|
||||||
python_version = 3.12
|
python_version = 3.13
|
||||||
platform = linux
|
platform = linux
|
||||||
plugins = pydantic.mypy, pydantic.v1.mypy
|
plugins = pydantic.mypy, pydantic.v1.mypy
|
||||||
show_error_codes = true
|
show_error_codes = true
|
||||||
|
@ -9,6 +9,8 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
|
from homeassistant.const import REQUIRED_PYTHON_VER
|
||||||
|
|
||||||
from .model import Config, Integration
|
from .model import Config, Integration
|
||||||
|
|
||||||
# Component modules which should set no_implicit_reexport = true.
|
# Component modules which should set no_implicit_reexport = true.
|
||||||
@ -29,18 +31,7 @@ HEADER: Final = """
|
|||||||
""".lstrip()
|
""".lstrip()
|
||||||
|
|
||||||
GENERAL_SETTINGS: Final[dict[str, str]] = {
|
GENERAL_SETTINGS: Final[dict[str, str]] = {
|
||||||
# We use @dataclass_transform in all our EntityDescriptions, causing
|
"python_version": ".".join(str(x) for x in REQUIRED_PYTHON_VER[:2]),
|
||||||
# `__replace__` to be already synthesized by mypy, causing **every** use of
|
|
||||||
# our entity descriptions to fail:
|
|
||||||
#
|
|
||||||
# error: Signature of "__replace__" incompatible with supertype "EntityDescription"
|
|
||||||
#
|
|
||||||
# Until this is fixed in mypy, we keep mypy locked on to Python 3.12 as we
|
|
||||||
# have done for the past few releases.
|
|
||||||
#
|
|
||||||
# Ref: https://github.com/python/mypy/issues/18216
|
|
||||||
# "python_version": ".".join(str(x) for x in REQUIRED_PYTHON_VER[:2]),
|
|
||||||
"python_version": "3.12",
|
|
||||||
"platform": "linux",
|
"platform": "linux",
|
||||||
"plugins": ", ".join( # noqa: FLY002
|
"plugins": ", ".join( # noqa: FLY002
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user