mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Enable pydantic mypy plugin (#87415)
This commit is contained in:
parent
2d2ff19949
commit
67499e0204
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@ -30,7 +30,7 @@ on:
|
|||||||
env:
|
env:
|
||||||
CACHE_VERSION: 5
|
CACHE_VERSION: 5
|
||||||
PIP_CACHE_VERSION: 4
|
PIP_CACHE_VERSION: 4
|
||||||
MYPY_CACHE_VERSION: 3
|
MYPY_CACHE_VERSION: 4
|
||||||
HA_SHORT_VERSION: 2023.3
|
HA_SHORT_VERSION: 2023.3
|
||||||
DEFAULT_PYTHON: "3.10"
|
DEFAULT_PYTHON: "3.10"
|
||||||
ALL_PYTHON_VERSIONS: "['3.10']"
|
ALL_PYTHON_VERSIONS: "['3.10']"
|
||||||
|
@ -255,7 +255,7 @@ class LaMetricFlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN):
|
|||||||
model=Model(
|
model=Model(
|
||||||
cycles=2,
|
cycles=2,
|
||||||
frames=[Simple(text="Connected to Home Assistant!", icon=7956)],
|
frames=[Simple(text="Connected to Home Assistant!", icon=7956)],
|
||||||
sound=Sound(id=NotificationSound.WIN),
|
sound=Sound(sound=NotificationSound.WIN),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -52,7 +52,7 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
sound = None
|
sound = None
|
||||||
if CONF_SOUND in data:
|
if CONF_SOUND in data:
|
||||||
sound = Sound(id=data[CONF_SOUND], category=None)
|
sound = Sound(sound=data[CONF_SOUND], category=None)
|
||||||
|
|
||||||
notification = Notification(
|
notification = Notification(
|
||||||
icon_type=NotificationIconType(data.get(CONF_ICON_TYPE, "none")),
|
icon_type=NotificationIconType(data.get(CONF_ICON_TYPE, "none")),
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
"""Support for LaMetric time services."""
|
"""Support for LaMetric time services."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Sequence
|
|
||||||
|
|
||||||
from demetriek import (
|
from demetriek import (
|
||||||
AlarmSound,
|
AlarmSound,
|
||||||
Chart,
|
Chart,
|
||||||
|
Goal,
|
||||||
LaMetricError,
|
LaMetricError,
|
||||||
Model,
|
Model,
|
||||||
Notification,
|
Notification,
|
||||||
@ -113,12 +112,12 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
|||||||
async def async_send_notification(
|
async def async_send_notification(
|
||||||
coordinator: LaMetricDataUpdateCoordinator,
|
coordinator: LaMetricDataUpdateCoordinator,
|
||||||
call: ServiceCall,
|
call: ServiceCall,
|
||||||
frames: Sequence[Chart | Simple],
|
frames: list[Chart | Goal | Simple],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Send a notification to an LaMetric device."""
|
"""Send a notification to an LaMetric device."""
|
||||||
sound = None
|
sound = None
|
||||||
if CONF_SOUND in call.data:
|
if CONF_SOUND in call.data:
|
||||||
sound = Sound(id=call.data[CONF_SOUND], category=None)
|
sound = Sound(sound=call.data[CONF_SOUND], category=None)
|
||||||
|
|
||||||
notification = Notification(
|
notification = Notification(
|
||||||
icon_type=NotificationIconType(call.data[CONF_ICON_TYPE]),
|
icon_type=NotificationIconType(call.data[CONF_ICON_TYPE]),
|
||||||
|
7
mypy.ini
7
mypy.ini
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
[mypy]
|
[mypy]
|
||||||
python_version = 3.10
|
python_version = 3.10
|
||||||
|
plugins = pydantic.mypy
|
||||||
show_error_codes = true
|
show_error_codes = true
|
||||||
follow_imports = silent
|
follow_imports = silent
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
@ -26,6 +27,12 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[pydantic-mypy]
|
||||||
|
init_forbid_extra = true
|
||||||
|
init_typed = true
|
||||||
|
warn_required_dynamic_aliases = true
|
||||||
|
warn_untyped_fields = true
|
||||||
|
|
||||||
[mypy-homeassistant.*]
|
[mypy-homeassistant.*]
|
||||||
no_implicit_reexport = true
|
no_implicit_reexport = true
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ freezegun==1.2.2
|
|||||||
mock-open==1.4.0
|
mock-open==1.4.0
|
||||||
mypy==1.0.0
|
mypy==1.0.0
|
||||||
pre-commit==3.0.0
|
pre-commit==3.0.0
|
||||||
|
pydantic==1.10.4
|
||||||
pylint==2.16.0
|
pylint==2.16.0
|
||||||
pylint-per-file-ignores==1.1.0
|
pylint-per-file-ignores==1.1.0
|
||||||
pipdeptree==2.3.1
|
pipdeptree==2.3.1
|
||||||
|
@ -37,6 +37,7 @@ HEADER: Final = """
|
|||||||
|
|
||||||
GENERAL_SETTINGS: Final[dict[str, str]] = {
|
GENERAL_SETTINGS: Final[dict[str, str]] = {
|
||||||
"python_version": ".".join(str(x) for x in REQUIRED_PYTHON_VER[:2]),
|
"python_version": ".".join(str(x) for x in REQUIRED_PYTHON_VER[:2]),
|
||||||
|
"plugins": ", ".join(["pydantic.mypy"]),
|
||||||
"show_error_codes": "true",
|
"show_error_codes": "true",
|
||||||
"follow_imports": "silent",
|
"follow_imports": "silent",
|
||||||
# Enable some checks globally.
|
# Enable some checks globally.
|
||||||
@ -84,6 +85,18 @@ STRICT_SETTINGS_CORE: Final[list[str]] = [
|
|||||||
"disallow_any_generics",
|
"disallow_any_generics",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Plugin specific settings
|
||||||
|
# Bump mypy cache when updating! Some plugins don't invalidate the cache properly.
|
||||||
|
# pydantic: https://docs.pydantic.dev/mypy_plugin/#plugin-settings
|
||||||
|
PLUGIN_CONFIG: Final[dict[str, dict[str, str]]] = {
|
||||||
|
"pydantic-mypy": {
|
||||||
|
"init_forbid_extra": "true",
|
||||||
|
"init_typed": "true",
|
||||||
|
"warn_required_dynamic_aliases": "true",
|
||||||
|
"warn_untyped_fields": "true",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _strict_module_in_ignore_list(
|
def _strict_module_in_ignore_list(
|
||||||
module: str, ignored_modules_set: set[str]
|
module: str, ignored_modules_set: set[str]
|
||||||
@ -132,7 +145,7 @@ def _generate_and_validate_strict_typing(config: Config) -> str:
|
|||||||
return "\n".join(_sort_within_sections(lines)) + "\n"
|
return "\n".join(_sort_within_sections(lines)) + "\n"
|
||||||
|
|
||||||
|
|
||||||
def _generate_and_validate_mypy_config(config: Config) -> str:
|
def _generate_and_validate_mypy_config(config: Config) -> str: # noqa: C901
|
||||||
"""Validate and generate mypy config."""
|
"""Validate and generate mypy config."""
|
||||||
|
|
||||||
# Filter empty and commented lines.
|
# Filter empty and commented lines.
|
||||||
@ -199,6 +212,13 @@ def _generate_and_validate_mypy_config(config: Config) -> str:
|
|||||||
for key in STRICT_SETTINGS:
|
for key in STRICT_SETTINGS:
|
||||||
mypy_config.set(general_section, key, "true")
|
mypy_config.set(general_section, key, "true")
|
||||||
|
|
||||||
|
for plugin_name, plugin_config in PLUGIN_CONFIG.items():
|
||||||
|
if not plugin_config:
|
||||||
|
continue
|
||||||
|
mypy_config.add_section(plugin_name)
|
||||||
|
for key, value in plugin_config.items():
|
||||||
|
mypy_config.set(plugin_name, key, value)
|
||||||
|
|
||||||
# By default enable no_implicit_reexport only for homeassistant.*
|
# By default enable no_implicit_reexport only for homeassistant.*
|
||||||
# Disable it afterwards for all components
|
# Disable it afterwards for all components
|
||||||
components_section = "mypy-homeassistant.*"
|
components_section = "mypy-homeassistant.*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user