Add type ignore error codes [helpers] (#66776)

This commit is contained in:
Marc Mueller
2022-02-18 11:31:37 +01:00
committed by GitHub
parent 0188e8b319
commit bfb1abd3a2
12 changed files with 25 additions and 23 deletions

View File

@@ -15,7 +15,9 @@ import logging
from numbers import Number
import os
import re
from socket import _GLOBAL_DEFAULT_TIMEOUT # type: ignore # private, not in typeshed
from socket import ( # type: ignore[attr-defined] # private, not in typeshed
_GLOBAL_DEFAULT_TIMEOUT,
)
from typing import Any, TypeVar, cast, overload
from urllib.parse import urlparse
from uuid import UUID
@@ -163,7 +165,7 @@ def boolean(value: Any) -> bool:
return False
elif isinstance(value, Number):
# type ignore: https://github.com/python/mypy/issues/3186
return value != 0 # type: ignore
return value != 0 # type: ignore[comparison-overlap]
raise vol.Invalid(f"invalid boolean value {value}")
@@ -421,7 +423,7 @@ def date(value: Any) -> date_sys:
def time_period_str(value: str) -> timedelta:
"""Validate and transform time offset."""
if isinstance(value, int): # type: ignore
if isinstance(value, int): # type: ignore[unreachable]
raise vol.Invalid("Make sure you wrap time values in quotes")
if not isinstance(value, str):
raise vol.Invalid(TIME_PERIOD_ERROR.format(value))
@@ -585,7 +587,7 @@ def template(value: Any | None) -> template_helper.Template:
if isinstance(value, (list, dict, template_helper.Template)):
raise vol.Invalid("template value should be a string")
template_value = template_helper.Template(str(value)) # type: ignore
template_value = template_helper.Template(str(value)) # type: ignore[no-untyped-call]
try:
template_value.ensure_valid()
@@ -603,7 +605,7 @@ def dynamic_template(value: Any | None) -> template_helper.Template:
if not template_helper.is_template_string(str(value)):
raise vol.Invalid("template value does not contain a dynamic template")
template_value = template_helper.Template(str(value)) # type: ignore
template_value = template_helper.Template(str(value)) # type: ignore[no-untyped-call]
try:
template_value.ensure_valid()
return template_value
@@ -796,7 +798,7 @@ def _deprecated_or_removed(
"""Check if key is in config and log warning or error."""
if key in config:
try:
near = f"near {config.__config_file__}:{config.__line__} " # type: ignore
near = f"near {config.__config_file__}:{config.__line__} " # type: ignore[attr-defined]
except AttributeError:
near = ""
arguments: tuple[str, ...]