This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Takuo Matsuoka
Recipients Takuo Matsuoka, ethan.furman, steven.daprano
Date 2022-04-07.05:12:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649308344.2.0.822231781591.issue47136@roundup.psfhosted.org>
In-reply-to
Content
Thank you Ethan for your comments.

Sure, I was not familiar with how you measure the magnitude of the
consequences.  The code in my own work was of the kind of the generic
example I gave, but I have abandoned the approach, and don't seem able
to find it any more.  I think the approach turned out not ideal for
the specific aim I had, which I'm sorry I can't recall now.

I might just say there may be circumstances where a not so thoughtful
programmer might get inclined to implementing a metaclass C in some
manner like:

```
class C(type(B)):
    # Skip __init__ .  It's just to help checking type later.
    def __init__(self, /, *args, **kwargs):
        super().__init__(*args, **kwargs)
        dict_ = self.__dict__
        try:
            name = dict_["__name__"]
        except KeyError:
            pass
        else:
            name._owner = self
    @classmethod
    def __prepare__(cls, /, *args, **kwargs):
        return dict(__name__ = cls._name(*args, **kwargs))
    @classmethod
    class _name:
        def __get__(self, instance, owner=None):
            if instance is None:
                if issubclass(owner, self_owner := self._owner):
                    return self
                else:
                    raise TypeError(f'{owner} is not a subclass of'
                                    f' {self_owner.__qualname__}')
            name = instance._super().__name__ # See the class O
            # below. 
            #
            #
            # Any procedure here, depending on what you'd like to do
            # with the instance of your class...
            #
            return name
        def __init__(self, cls, /, *args, **kwargs): ......
        def __set__(self, instance, value): ......
        def __delete__(self, instance): ......
```

where she creates instances of the metaclass C by inheriting from:

```
class O(B, metaclass=C):
    def _super(self):
        return super()
    def __init_subclass__(cls, /, *args, **kwargs):
        return super().__init_subclass__(*args)
```

Another thing I can say is code that does something like that is not
what I write often or even had written before, I guess.  Still, I
reported the issue thinking some people (possibly including myself)
may come around the kind of code some time in the future again.

If the behaviour is not going to be changed, then I think the
documentation should at least be made sure to warn about it.  I don't
think the behaviour can be expected without documentation.

Thanks.
History
Date User Action Args
2022-04-07 05:12:24Takuo Matsuokasetrecipients: + Takuo Matsuoka, steven.daprano, ethan.furman
2022-04-07 05:12:24Takuo Matsuokasetmessageid: <1649308344.2.0.822231781591.issue47136@roundup.psfhosted.org>
2022-04-07 05:12:24Takuo Matsuokalinkissue47136 messages
2022-04-07 05:12:23Takuo Matsuokacreate