Use singleton enum for "not set" sentinels (#41990)

* Use singleton enum for "not set" sentinel

https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions

* Remove unused variable
This commit is contained in:
Ville Skyttä
2020-12-19 13:46:27 +02:00
committed by GitHub
parent de04a1ed67
commit 317ed418dd
11 changed files with 139 additions and 131 deletions

View File

@@ -1,4 +1,5 @@
"""Typing Helpers for Home Assistant."""
from enum import Enum
from typing import Any, Dict, Mapping, Optional, Tuple, Union
import homeassistant.core
@@ -16,3 +17,12 @@ TemplateVarsType = Optional[Mapping[str, Any]]
# Custom type for recorder Queries
QueryType = Any
class UndefinedType(Enum):
"""Singleton type for use with not set sentinel values."""
_singleton = 0
UNDEFINED = UndefinedType._singleton # pylint: disable=protected-access