New submission from Gobot1234 <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue46743>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com