这是indexloc提供的服务,不要输入任何密码
Skip to content

Corner case: What about built-in generics' subclasses? #9

@bswck

Description

@bswck

To ensure full compatibility, I think that

from typing import ForwardRef
from eval_type_backport import eval_type_backport

class DictSubclass(dict):
    pass

eval_type_backport(ForwardRef('DictSubclass[str, int]'), globals())

should not raise an error on Python 3.8, since it doesn't on Python 3.9.

Normally you would re-bind the Generic signature, using

KT = TypeVar('KT')
VT = TypeVar('VT')

class DictSubclass(dict[KT, VT], Generic[KT, VT]):
    ...

but we know that in Python 3.8 it's simply impossible without subclassing typing.Dict.

What do you think?

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