[issue44057] Inconsitencies in `__init_subclass__` in a generic class

2021-05-06 Thread Erez Zinman
Erez Zinman added the comment: Also Tensorflow. -- ___ Python tracker <https://bugs.python.org/issue44057> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue44057] Inconsitencies in `__init_subclass__` in a generic class

2021-05-06 Thread Erez Zinman
Erez Zinman added the comment: You're right. I accidentally used 3.6.9 both times. Thank you anyway. Regardless, that's unfortunate that you don't support the version 3.8 anymore, since many frameworks do not officially support 3.9 as of yet (pytorch, for example

[issue44057] Inconsitencies in `__init_subclass__` in a generic class

2021-05-06 Thread Erez Zinman
New submission from Erez Zinman : The following behavior was witnessed in v3.6 & v3.8. When deriving from a Generic base class, there's an inconsistency in the order of operation within the `__new__()` function between the case of deriving WITH generic-argument specification and WIT

[issue43595] Can not add a metclass that inherits both ABCMeta & ABC to a Union

2021-03-22 Thread Erez Zinman
Erez Zinman added the comment: This is actually a lot worse and unrelated to the aforementioned issue. The code ``` from typing import Union from abc import ABC Union[str, ABC] ``` raises the exception >>> TypeError: descriptor '__subclasses__' of 'type' object needs an

[issue43595] Can not add a metclass that inherits both ABCMeta & ABC to a Union

2021-03-22 Thread Erez Zinman
New submission from Erez Zinman : Related to Issue #43594. When running the following code ``` from abc import ABCMeta, ABC from typing import Union class MetaclassMixin(ABC): pass class Meta(MetaclassMixin, ABCMeta): pass print(Union[str, Meta]) ``` An exception is raised

[issue43594] A metaclass that inherits both `ABC` and `ABCMeta` breaks on `__subclasscheck__`

2021-03-22 Thread Erez Zinman
New submission from Erez Zinman : Consider the following example: ``` from abc import ABCMeta, ABC class MetaclassMixin(ABC): pass class Meta(MetaclassMixin, ABCMeta): pass class A(metaclass=Meta): pass ``` Then the call `isinstance(A, Meta)` returns `True` but `isinstance(1

[issue43010] @functools.wraps and abc.abstractmethod interoperability

2021-03-22 Thread Erez Zinman
Erez Zinman added the comment: This is an interoperability bug. Maybe not a severe one (due to the workaround), but it's still a bug. -- ___ Python tracker <https://bugs.python.org/issue43

[issue43010] @functools.wraps and abc.abstractmethod interoperability

2021-03-22 Thread Erez Zinman
Erez Zinman added the comment: I haven't because I don't need it anymore and it will surely work. Yet by doing so, other attributes will not be copied. I think that the `abc`-related attributes are irrelevant regardless, and should be omitted (at least by default

[issue43010] @functools.wraps and abc.abstractmethod interoperability

2021-03-22 Thread Erez Zinman
Erez Zinman added the comment: Sorry for the late response. I forgot about that. I believe one of us misunderstands the problem. The problem is that `functools.wraps` copies the `__isabstractmethod__` in the first place. Consider the following example: ``` class ModuleTemplate(ABC

[issue43010] @functools.wraps and abc.abstractmethod interoperability

2021-01-23 Thread Erez Zinman
New submission from Erez Zinman : Consider the following code: ``` from abc import ABC, abstractmethod from functools import wraps class A(ABC): @abstractmethod def f(self): pass @wraps(f) def wrapper(self): print('f is called!') f() class

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
Erez Zinman added the comment: Just to be clear, what I did is (works with both "copy" and "pickle"): ``` def _new_and_init(cls): inst = cls.__new__(cls) OrderedDict.__init__(inst) return inst class A(OrderedDict): def __reduce__(self):

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
Erez Zinman added the comment: The first argument can be remedied by creating a new method that deals with that (something like `def _new_init(cls)`, and passing the `cls` as argument). The third argument is not really an argument - there is a bug that needs a precedent to be solved

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
Erez Zinman added the comment: small correction: meant `self.__class__` in the above function. Also, it is based on https://github.com/python/cpython/blob/76553e5d2eae3e8a47406a6de4f354fe33ff370b/Lib/collections/__init__.py#L302 -- ___ Python

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
Erez Zinman added the comment: Looking at the implementation of `__init__` (https://github.com/python/cpython/blob/76553e5d2eae3e8a47406a6de4f354fe33ff370b/Lib/collections/__init__.py#L109), it seems that you can fix this bug while retaining backward compatibility if you would use `__new__

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
Erez Zinman added the comment: Proposed solution - change OrderedDict's `__reduce_ex__ ` function. The code below works like expected if I override `__reduce_ex__` like so: ``` def __reduce_ex__(self, protocol): ret = list(super().__reduce_ex__(protocol)) ret[0] = type

[issue41751] Error copying an instance of a subclass of OrderedDict

2020-09-09 Thread Erez Zinman
New submission from Erez Zinman : This bug occurs when copying/pickling an ordered-dict subtype that has default items. The initialization function that's returned is **not** `object.__new__` so the default items are set when the copied/pickled item is created. The problem I encountered