[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-13 Thread Brandt Bucher
Change by Brandt Bucher : -- nosy: +brandtbucher ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: All typing related tests are fixed by updating types.GenericAlias.__getattribute__. So the only thing is left to make all tests passed is removing some special methods tests. The lookup of __instancecheck__ and __subclasscheck__ was changed by Benjamin in

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Guido van Rossum
Guido van Rossum added the comment: I believe that the PEP 3119 example doesn't work (I've confirmed something simpler) but I have a feeling that the uses of __instancecheck__ in typing.py are actually okay. For example, isinstance(42, typing.Any) correctly calls _SpecialForm.__instancecheck__

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: Here's an example in PEP 3119 that appears to work but actually bypasses the method: from abc import ABCMeta, abstractmethod class Sized(metaclass=ABCMeta): @abstractmethod def __hash__(self): return 0 @classmethod def __instancech

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Most of failed tests are related to typing, but there is a purposed test for __instancecheck__ and __subclasscheck__ bypassing __getattr__ and __getattribute__ (test.test_descr.ClassPropertiesAndMethods.test_special_method_lookup). -- ___

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: I did a scan of the standard library and code in the wild. It looks like almost all uses are in metaclasses (which makes sense because that matches the AppendableSequence example in PEP 3119). However, the typing module does have some cases of __instance

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Failed tests: == FAIL: test_isinstance_with_or_union (test.test_isinstance.TestIsInstanceIsSubclass) -- Traceback (most r

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- keywords: +patch pull_requests: +27789 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29540 ___ Python tracker ___

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, I discovered the issue when experimenting with ways to use the class pattern in structural pattern matching. --- Code that should work but doesn't --- class Warm: def __instancecheck__(cls, inst): return inst in {'red', 'orange'

[issue45791] __instancecheck__ being checked on type(cls) instead of cls

2021-11-12 Thread Raymond Hettinger
Change by Raymond Hettinger : -- title: __instancecheck__ being checked of type(cls) instead of cls -> __instancecheck__ being checked on type(cls) instead of cls ___ Python tracker _