[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread miss-islington
miss-islington added the comment: New changeset b42eee78e7651693aa38c390f577e5d499dcf55d by Miss Islington (bot) in branch '3.10': bpo-44606: Fix __instancecheck__ and __subclasscheck__ for the union type. (GH-27120)

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 81989058de381108dfd0a4255b93d4fb34417002 by Serhiy Storchaka in branch 'main': bpo-44606: Fix __instancecheck__ and __subclasscheck__ for the union type. (GH-27120)

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread miss-islington
Change by miss-islington : -- nosy: +miss-islington nosy_count: 3.0 -> 4.0 pull_requests: +25675 pull_request: https://github.com/python/cpython/pull/27132 ___ Python tracker

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Ken Jin
Ken Jin added the comment: > 3. There is also a crash in isinstance(): That's unfortunate :(. Serhiy, thanks for catching all these bugs in union. I recently realized you probably made 50% of all bug reports for union and they're very much appreciated :). > Converting None to type(None)

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PR 27120 fixes __instancecheck__ and __subclasscheck__. Converting None to type(None) will be done in other PR. -- ___ Python tracker ___

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- type: behavior -> crash ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- keywords: +patch pull_requests: +25665 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27120 ___ Python tracker

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: 3. There is also a crash in isinstance(): >>> class BadMeta(type): ... def __instancecheck__(cls, inst): ... 1/0 ... >>> x = int | BadMeta('A', (), {}) >>> isinstance([], x) Fatal Python error: _Py_CheckFunctionResult: a function returned a

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Ken Jin
Ken Jin added the comment: @Serhiy, can I work on converting None to type(None) please? -- ___ Python tracker ___ ___

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Guido van Rossum
Guido van Rossum added the comment: Converting None to type(None) is fine, as long as the str() /repr() converts it back, e.g. repr(int | None) should print just that, not NoneType.-- --Guido (mobile) -- ___ Python tracker

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Ken Jin
Ken Jin added the comment: @Serhiy > 2. Different handling of virtual subclasses: This looks like a bug. I think the union form of isinstance/issubclass should have the same behavior as the tuple form. We promise checking of virtual classes in the docs for union types:

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I have found this when refactored the code of Objects/unionobject.c. So I have a patch which fixes this, but I want to make sure what behavior is considered correct. -- ___ Python tracker

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-12 Thread Guido van Rossum
Guido van Rossum added the comment: Ken Jin, should we treat type(None) as a subclass of int|None? -- nosy: +kj ___ Python tracker ___

[issue44606] Discrepancy between isinstance() and issubclass() for union types

2021-07-11 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : 1. Different handling of None: >>> isinstance(None, int | type(None)) True >>> issubclass(type(None), int | type(None)) True >>> isinstance(None, int | None) True >>> issubclass(type(None), int | None) False 2. Different handling of virtual subclasses: