Re: [Python-ideas] A way out of Meta-hell (was: A (meta)class algebra)
On Mon, Feb 16, 2015 at 5:16 PM, Martin Teichmann
Hi list,
Again, Python already has a metaclass that everyone is supposed to use, namely `type`.
well, there is a problem out here: people are indeed using other metaclasses. Even the standard library, like ABC or enums.
And there is a problem here in python: once you do multiple inheritance, and two classes have different metaclasses, there is no way of programmatically determining an appropriate metaclass.
Sure, one can be of Thomas' opinion that doing so is a bad idea anyways, but there are other people who think that writing and combining metaclasses actually is thing one can do.
Especially for simple cases I do think that metaclasses are a good idea and there should be a way to tell python how to combine two metaclasses.
I am trying to solve this problem. What I posted was just one simple idea how to solve it. Another one is the idea I posted earlier, the idea was to add metaclasses using __add__. People didn't like the __add__, so I implemented that with a new method called merge, it's here: https://github.com/tecki/cpython/commits/metaclass-merge
Instead of yelling at me that my solutions are too complicated,
Hello, I am very sorry that my post came across as yelling. I had no intention of that, though on re-reading it is rather harsh. I will try to be less confrontational in the future. The meta-metaclass approach is no doubt ingenious, but most people struggle with the concept of metaclasses, so building a more complex thing on top is quite tricky. And while I'd like to be proven wrong, I think fleshing out the details would complicate things even further.
it would be very helpful and constructive to answer the following questions:
- is it desirable to have a programmatic way to combine metaclasses?
That's not a simple yes/no answer. If you are asking if there should be a generic way to merge any two metaclasses, then the answer is "no": metaclasses are too powerful to merge two of them safely without knowing details about both. If you are asking about merging two metaclasses when knowing all the details, then the answer is "yes" – but there is already a way to do this, namely a new metaclass deriving from both. The discussion is about whether it's desirable to do this subclassing automatically, so that one of the metaclasses describes how it is to be combined with the other. And my answer to that is: no, I don't think it's worth the extra complexity. If you truly need the full power of metaclasses, then to combine any two of them you need to know all the details; it is better to create the subclass explicitly. For simple cases – and here we seem to disagree – I think metaclasses *are* a bad idea. This is why I like PEP 422: taking the features that *can* be safely automatically combined, and letting you combine them through super()-style cooperative inheritance – which, while still far from trivial, is far more approachable than metaclasses. More generally, I think simple things should be built on simple things, not on complex things with more code added on top.
- if yes, how should that be done?
My idea is that yes, it is desirable to have a programmatic way of combining metaclasses, and I have now proposed two ways how to do that.
I still think your other effort – https://github.com/tecki/metaclasses – is a good solution, provided PEP 422 makes it into Python itself so that this code is used as a backwards compatibility shim. Forgive my lack of comments on that: I think that at this point, it's time to look for and iron out subtle issues in the idea/implementation, and I've not had time to study them in enough detail yet. I should have expressed more enthusiasm, rather than waiting until I was sure I couldn't find obvious flaws. So here it is: I think PEP 422, and your Github repo, are definitely headed in the right direction. Meanwhile I shouted it down the meta-metaclass idea as soon as I saw it's heading the wrong direction – towards complicating things. I am too biased towards negativity. Please accept my apology. Also, a disclaimer: I'm not a Python core developer. Pay much more attention to Nick's words than mine.
I am trying to solve this problem. What I posted was just one simple idea how to solve it. Another one is the idea I posted earlier, the idea was to add metaclasses using __add__. People didn't like the __add__, so I implemented that with a new method called merge, it's here: https://github.com/tecki/cpython/commits/metaclass-merge
Instead of yelling at me that my solutions are too complicated,
Hello, I am very sorry that my post came across as yelling. I had no intention of that, though on re-reading it is rather harsh. I will try to be less confrontational in the future.
No. I'm sorry, but this needs to be responded to. I'm a lurker, and find this discussion barely interesting at its best -- I've never had to combine metaclasses and no compelling case has been shown to my mind to interest me in fixing a so-called problem. That said: In no way, shape or form did Petr "yell" at you. In no way shape or form was his response not an entirely technical argument made with detail and consideration. Its wholly inappropriate to respond to a criticism or critique with an accusation of "yelling" or implying your point of view is being bullied when its simply someone showing disagreement. No one yelled. No one was in any way even kind of abrasive or rude. Someone disagreed and laid out why. To come back on them with an accusation of yelling-- bullying, really-- is inappropriate, at best. Please don't do it. That said: I really don't think you've made a case for what this is solving. I've used metaclasses many times, and have never run into this issue. I know there's some problems when Python is bridging with foreign object models-- ie, QT-- but does this really solve it? Is it really needed, and what's easier? To my reading of the thread previous, there were several people thinking that metaclasses were nuanced and problematic, but not that the problems you're trying to solve are fixable or even meaningful in context. People saying "there are issues with metaclasses" do not create a consensus to solve it by... this... thing... you're proposing is an their consensus. I don't know what its supposed to answer. All in all, this entire thread just makes me disinterested immediately as "not a problem", personally. What's wrong that you're solving? You want to combine metaclasses -- but that entire idea seems slightly nonsensical to me because how do you know what any metaclass will do? Meta-metaclasses sounds like a rabbit hole without a destination in mind.
On Fri, Feb 20, 2015 at 11:11 AM, Stephen Hansen
I am trying to solve this problem. What I posted was just one simple idea how to solve it. Another one is the idea I posted earlier, the idea was to add metaclasses using __add__. People didn't like the __add__, so I implemented that with a new method called merge, it's here: https://github.com/tecki/cpython/commits/metaclass-merge
Instead of yelling at me that my solutions are too complicated,
Hello, I am very sorry that my post came across as yelling. I had no intention of that, though on re-reading it is rather harsh. I will try to be less confrontational in the future.
No. I'm sorry, but this needs to be responded to.
I'm a lurker, and find this discussion barely interesting at its best -- I've never had to combine metaclasses and no compelling case has been shown to my mind to interest me in fixing a so-called problem.
That said: In no way, shape or form did Petr "yell" at you. In no way shape or form was his response not an entirely technical argument made with detail and consideration. Its wholly inappropriate to respond to a criticism or critique with an accusation of "yelling" or implying your point of view is being bullied when its simply someone showing disagreement.
No, Martin had every right to call me out. I have offended, thus I was rude. It was my mistake. That said, I'm rude quite often – when I misjudge someone's sensitivity for rudeness, chances are I'm rude. It happens, and I am honestly sorry for it, so I try to correct it. You might also notice that there was nothing I lost by apologizing. And I would have nothing to gain by questioning Martin's right to feel offended.
No one yelled. No one was in any way even kind of abrasive or rude. Someone disagreed and laid out why.
Nonsense. Rudeness is a spectrum; it is impossible to be absolutely non-abrasive, just as like no code can be absolutely elegant. I think that strictly adhering to some expected threshold of rudeness in a list like this is harmful. It keeps some people out of the conversation. It is much better to take individual people into account. Being called out when something I write turns out to be offensive is necessary for calibrating the proper level of rudeness. I'd like to thank Martin for saying it directly, so I had a chance to defuse a grudge promptly.
To come back on them with an accusation of yelling-- bullying, really-- is inappropriate, at best. Please don't do it.
That said: I really don't think you've made a case for what this is solving.
I've used metaclasses many times, and have never run into this issue. I know there's some problems when Python is bridging with foreign object models-- ie, QT-- but does this really solve it? Is it really needed, and what's easier? To my reading of the thread previous, there were several people thinking that metaclasses were nuanced and problematic, but not that the problems you're trying to solve are fixable or even meaningful in context. People saying "there are issues with metaclasses" do not create a consensus to solve it by... this... thing... you're proposing is an their consensus. I don't know what its supposed to answer.
All in all, this entire thread just makes me disinterested immediately as "not a problem", personally. What's wrong that you're solving? You want to combine metaclasses -- but that entire idea seems slightly nonsensical to me because how do you know what any metaclass will do?
Meta-metaclasses sounds like a rabbit hole without a destination in mind.
You might not have run into the problem at hand, but it clearly is a problem for others. This thread is looking for a solution that would not be unnecessarily complicated for people who don't care. I think that at this point, the discussion is past the questions you are asking. Most have been asked, and mostly answered, in different words above. If you find one that hasn't, could you ask a more focused question?
On Fri, Feb 20, 2015 at 02:33:05PM +0100, Petr Viktorin wrote:
No, Martin had every right to call me out. I have offended, thus I was rude. It was my mistake.
One can give offense, or the other can take offense. There are people who take offense at the mere existence of homosexuals, or women who show their face in public, or black people wanting access to the same opportunities as white people. That does not mean that homosexuals, women or blacks have *given* offense, only that some people will *take* offense when it suits their alterior motives. I do not believe you said anything to Martin that gives offense. I'm not even sure that Martin took offense. As I recall, he merely said he had been yelled at, which is a much milder comment: "Instead of yelling at me...". All the posts I've read have been quiet, respectful, and have treated Martin fairly even if they have been critical of his ideas.
Being called out when something I write turns out to be offensive is necessary for calibrating the proper level of rudeness.
This is a community. Neither Martin nor you get to decide alone what the "proper level of rudeness" is. We all should keep in mind the meaning of the word "offend", and don't mistake mere vigorous disagreement for offensive behaviour. Offend: To displease; to make angry; to affront. (Websters) An affront is a designed mark of disrespect, usually in the presence of others. An insult is a personal attack either by words or actions, designed to humiliate or degrade. An outrage is an act of extreme and violent insult or abuse. An affront piques and mortifies; an insult irritates and provokes; an outrage wounds and injures. (The Collaborative International Dictionary of English) -- Steve
participants (3)
-
Petr Viktorin
-
Stephen Hansen
-
Steven D'Aprano