Skip to content

ObjectProxy does not play well with GenericAlias, such as isinstance(proxy, Dict)  #245

@champialex

Description

@champialex

Thanks for the great library!

Just ran into an issue with instance checks on typing.py aliases.

def test_isinstance_proxy():
    p = wrapt.ObjectProxy({1: 2})

    assert isinstance(p, dict) # Passes just fine
    assert isinstance(p, Dict) # Fails

This is due to GenericAlias / _BaseGenericAlias being implemented as:

def __instancecheck__(self, obj):
    return self.__subclasscheck__(type(obj)) # Should be obj.__class__

I imagine this is a python bug? Is this something you have run into before?

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