# Contravariant typing.Type?

**URL:** <https://discuss.python.org/t/contravariant-typing-type/12741>\
**Category:** Python Help\
**Created:** [December 25, 2021, 7:34pm UTC](https://discuss.python.org/t/contravariant-typing-type/12741 "2021-12-25T19:34:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prryplatypus](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/prryplatypus/32/5801_2.png) [@prryplatypus](https://discuss.python.org/u/prryplatypus)\
**Post date:** [December 25, 2021, 7:34pm UTC](https://discuss.python.org/t/contravariant-typing-type/12741/1 "2021-12-25T19:34:32Z")

</div>

Hi all, first time posting here.

I’m currently trying to enforce typing checks such that I can only pass the “choices” parameter in the following snippet of code if the “type\_” parameter is one of “int”, “str” or “float”. Unfortunately, when I pass “bool” typing checks succeed as -from what I’ve been able to gather- “typing.Type” is covariant, and since “bool” subclasses “int”, it is then interpreted as such.

```auto
T = TypeVar("T", int, str, float)

class Choice(Generic[T]):
    value: T
    def __init__ (self, name: str, value: T) -> None: ...
    def _to_dict(self) -> Dict[str, Any]: ...

class Parameter:
    @overload
    def __init__ (
        self,
        type_: Type[bool],
        name: str,
        description: str,
        required: bool = True,
    ) -> None: ...

    @overload
    def __init__ (
        self,
        type_: Type[T],
        name: str,
        description: str,
        required: bool = True,
        choices: Optional[List[Choice[T]]] = None,
    ) -> None: ...

    def __init__ (
        self,
        type_: Union[Type[bool], Type[T]],
        name: str,
        description: str,
        required: bool = True,
        choices=None,
    ) -> None: ...

```

Here’s an example that’s passing typechecks when I wouldn’t want it to:

```auto
Parameter(
    type_=bool,
    name="everyone",
    description='Whether to mention everyone',
    choices=[]
)

```

I’ve been searching for hours, but I’ve been struggling to find any solution or workaround for this specific issue. Would anyone here happen to know how I could possibly fix this?
