Improve typing via hassfest serializer (#117382)
parent
1985a2ad8b
commit
2e68363755
|
@ -5,7 +5,9 @@ To update, run python3 -m script.hassfest
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
BLUETOOTH: list[dict[str, bool | str | int | list[int]]] = [
|
||||
from typing import Final
|
||||
|
||||
BLUETOOTH: Final[list[dict[str, bool | str | int | list[int]]]] = [
|
||||
{
|
||||
"domain": "airthings_ble",
|
||||
"manufacturer_id": 820,
|
||||
|
|
|
@ -7,7 +7,11 @@ to the political situation in the world, please contact the ISO 3166 working gro
|
|||
|
||||
"""
|
||||
|
||||
COUNTRIES = {
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
COUNTRIES: Final[set[str]] = {
|
||||
"AD",
|
||||
"AE",
|
||||
"AF",
|
||||
|
|
|
@ -5,7 +5,9 @@ To update, run python3 -m script.hassfest
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
DHCP: list[dict[str, str | bool]] = [
|
||||
from typing import Final
|
||||
|
||||
DHCP: Final[list[dict[str, str | bool]]] = [
|
||||
{
|
||||
"domain": "airzone",
|
||||
"macaddress": "E84F25*",
|
||||
|
|
|
@ -24,5 +24,6 @@ Path("homeassistant/generated/countries.py").write_text(
|
|||
"COUNTRIES": countries,
|
||||
},
|
||||
generator=generator_string,
|
||||
annotations={"COUNTRIES": "Final[set[str]]"},
|
||||
)
|
||||
)
|
||||
|
|
|
@ -20,7 +20,9 @@ def generate_and_validate(integrations: dict[str, Integration]) -> str:
|
|||
|
||||
return format_python_namespace(
|
||||
{"BLUETOOTH": match_list},
|
||||
annotations={"BLUETOOTH": "list[dict[str, bool | str | int | list[int]]]"},
|
||||
annotations={
|
||||
"BLUETOOTH": "Final[list[dict[str, bool | str | int | list[int]]]]"
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ def generate_and_validate(integrations: dict[str, Integration]) -> str:
|
|||
|
||||
return format_python_namespace(
|
||||
{"DHCP": match_list},
|
||||
annotations={"DHCP": "list[dict[str, str | bool]]"},
|
||||
annotations={"DHCP": "Final[list[dict[str, str | bool]]]"},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -102,6 +102,6 @@ def format_python_namespace(
|
|||
for key, value in sorted(content.items())
|
||||
)
|
||||
if annotations:
|
||||
# If we had any annotations, add the __future__ import.
|
||||
code = f"from __future__ import annotations\n{code}"
|
||||
# If we had any annotations, add __future__ and typing imports.
|
||||
code = f"from __future__ import annotations\n\nfrom typing import Final\n{code}"
|
||||
return format_python(code, generator=generator)
|
||||
|
|
Loading…
Reference in New Issue