Skip to content

cannot inherit from a parameters  #14185

@samsja

Description

@samsja

Bug Report

It seems that mypy does not allow to inherit from a parameter when creating a function on the fly.

To Reproduce

from typing import Type


def f(cls: Type) -> Type:


    class A(cls):
        ...
    
    return A

>>>file.py:6: error: Variable "cls" is not valid as a type  [valid-type]
>>>file.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
>>>file.py:6: error: Invalid base class "cls"  [misc]

Expected Behavior

Mypy should not complain

Actual Behavior

Mypy complain and say

>>>file.py:6: error: Variable "cls" is not valid as a type  [valid-type]
>>>file.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
>>>file.py:6: error: Invalid base class "cls"  [misc]

Your Environment

  • Mypy version used:`0.990
  • Python version used: 3.9.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions