def decode_raw(self, data: bytes) -> List[HeaderTuple]:
...
if not typing.TYPE_CHECKING:
def decode(self, data, bytes):
return [_unicode_if_needed(h, raw) for h in self.decode_raw()]
`
@attr.frozen
but it needs to subclass tuple
type(NEED_DATA) is NEED_DATA
which I don't think is possible for Enum values.
isinstance(v, NEED_DATA)
?
if TYPE_CHECKING
and the current code in the else
?
_SentinelClient = NewType("_SentinelClient", Sentinel)
CLIENT: Final[_SentinelClient] = create_sentinel("CLIENT")
class CLIENT(Sentinel):
pass
CLIENT.__class__ = CLIENT
from typing import TypeVar, Type, Tuple, Any, Dict
_T_Sentinel = TypeVar("_T_Sentinel", bound="Sentinel")
class Sentinel(type):
def __new__(
cls: Type[_T_Sentinel],
name: str,
bases: Tuple[type, ...],
namespace: Dict[str, Any],
**kwds: Any
) -> _T_Sentinel:
assert bases == (Sentinel, )
return super().__new__(cls, name, bases, namespace, **kwds)
def __repr__(self) -> str:
return self.__name__
def __init_subclass__(cls: "Type[Sentinel]", **kwargs: Dict[str, Any]) -> None:
super().__init_subclass__(**kwargs) # type: ignore
cls.__class__ = cls # type: ignore
class CLIENT(Sentinel, metaclass=Sentinel):
pass
class CLIENT(Sentinel, metaclass=Sentinel): ...
from typing import TypeVar, Type, Tuple, Any, Dict
_T_Sentinel = TypeVar("_T_Sentinel", bound="Sentinel")
class Sentinel(type):
def __new__(
cls: Type[_T_Sentinel],
name: str,
bases: Tuple[type, ...],
namespace: Dict[str, Any],
**kwds: Any
) -> _T_Sentinel:
assert bases == (Sentinel, )
v = super().__new__(cls, name, bases, namespace, **kwds)
v.__class__ = v # type: ignore
return v
def __repr__(self) -> str:
return self.__name__
class CLIENT(Sentinel, metaclass=Sentinel):
pass