[New-bugs-announce] [issue46743] Enable usage of object.__orig_class__ in __init__
Gobot1234
report at bugs.python.org
Sun Feb 13 18:49:55 EST 2022
New submission from Gobot1234 <gobot1234yt at gmail.com>:
When using `__call__` on a `typing/types.GenericAlias` `__orig_class__` is set to the `GenericAlias` instance, however currently the mechanism for this does not allow the `__origin__` to access the `GenericAlias` from `__origin__.__init__` as it performs something akin to:
```py
def __call__(self, *args, **kwargs):
object = self.__origin__(*args, **kwargs)
object.__orig_class__ = self
return object
```
I'd like to propose changing this to something like:
```py
def __call__(self, *args, **kwargs):
object = self.__origin__.__new__(*args, **kwargs)
object.__orig_class__ = self
object.__init__(*args, **kwargs)
return object
```
(Ideally `__orig_class__` should also be available in `__new__` but I'm not entirely sure if that's possible)
AFAICT this was possible in the typing version back in 3.6 (https://github.com/python/typing/issues/658 and maybe https://github.com/python/typing/issues/519). Was there a reason this was removed?
----------
components: Library (Lib)
messages: 413198
nosy: Gobot1234, gvanrossum, kj
priority: normal
severity: normal
status: open
title: Enable usage of object.__orig_class__ in __init__
type: enhancement
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46743>
_______________________________________
More information about the New-bugs-announce
mailing list