Skip to content

"User defined generic does not accept provided constraints" error when 'Type' is used in hint #68

@smarie

Description

@smarie

PEP484 allows TypeVar to be used anywhere, not necessarily in Generic classes, see this section.

However as of today the following fails:

from enforce import runtime_validation
from typing import TypeVar, Type

T = TypeVar('T', bound=int)


@runtime_validation
class Foo:
    def foo(self, arg: Type[T]) -> T:
        return arg()

With error:

(...)
  File "C:\Miniconda3\envs\baseenv\lib\site-packages\enforce\enforcers.py", line 206, in generate_new_enforcer
    raise TypeError('User defined generic does not accept provided constraints')
TypeError: User defined generic does not accept provided constraints

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions