Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Custom abstract generic sub-classes #2291

Closed
@chadrik

Description

@chadrik

The second class definition fails type-checking with Invalid type "mymodule.T":

T = TypeVar('T')

class MyAbstractGeneric(Generic[T]):
    pass

class MyGeneric(MyAbstractGeneric[T]):
    pass

There's no documentation on creating custom abstract generic classes, and mypy and the typing tests have no examples of this either. The most obvious examples are those in typing itself, but it apparently uses techniques that are off limits outside of typing. I would love to know how to use multiple levels of inheritance to build up custom generics.

This is related to #606 but I did not want to derail the discussion there as my issue is more focused on creating generics rather than aliasing them. Maybe just user error.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions