I've got a generic container class:
from typing import Container, Generic, TypeVar, NamedTuple import sys fixed_typing = (sys.version_info >= (3, 6, 2) or (3, 5, 3) <= sys.version_info < (3, 6)) T = TypeVar("T") _Interval = NamedTuple("_Interval", [("start", int), ("stop", int), ("data", T)]) class Interval(_Interval, Container, Generic[T]): if fixed_typing: __slots__ = () ...
As you might've noticed there is a switch controlling the usage of
__slots__ during class initialisation. Basically, I'd like to use slots whenever possible, but older versions of the
typing module do not support slots in generic classes due to a bug. Is it okay to use the switch from the code design perspective? I've never seen it before, that's why I'm wondering. I find it similar to checking compiler flags using the preprocessor in C/C++, which is a common thing to do.