Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
Peristarkawan
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
4 ms
·
1.
▲
by
Peristarkawan
15y ago
I apologize. It was late, and my supply of patience for the day was exhausted.
2.
▲
by
Peristarkawan
15y ago
Sigh. No, that is not at all how super works in Python. The equivalent code to that Go function would be: def read_and_write(self): Reader.read(self) Writer.write(self) That is, if you want to get at a particular superc
3.
▲
by
Peristarkawan
15y ago
I mistyped. I meant "subclass OrderedCounter to add in the __missing__ method".
4.
▲
by
Peristarkawan
15y ago
Not really. The only thing that changed about super in Python 3 is that you can call it with no arguments, which is just a short-hand for the way it was already used in Python 2. Everything in that article applies equally to both Python v
5.
▲
by
Peristarkawan
15y ago
The version that I was rewriting: def __init__(self, shapename=None, **kwds): also allows that.
6.
▲
by
Peristarkawan
15y ago
That's true. The second one might be better written as: def __init__(self, shapename, **kwds): Or, in Python 3: def __init__(self, *, shapename, **kwds): (making shapename a required keyword-only argument)
7.
▲
by
Peristarkawan
15y ago
That's entirely the caller's fault, not the function's. Compare: >>> def init(**kwargs): ... pass ... >>> init(shapename='circle', **{'shapename': 'circle'}) Traceback (most recent call last): File
8.
▲
by
Peristarkawan
15y ago
I disagree, that's extremely fragile. It might work for the particular class you are implementing. However, it might cause subclasses of that class to break, since those subclasses will have a different MRO than the current class, and y
9.
▲
by
Peristarkawan
15y ago
The reason for using keywords is that there is no guarantee that the next class in the MRO after ColoredShape will be Shape. When the instance is a ColoredShape, it will be, but if ColoredShape is subclassed with a more complex inheritance
10.
▲
by
Peristarkawan
15y ago
Okay, I give. What's the markup for posting code snippets on this site?
11.
▲
by
Peristarkawan
15y ago
It seems to me that the example of combining built-in dictionary classes is naively optimistic. For starters, OrderedDict, as it happens, does not use super! It calls the dict super-class methods directly. Since dict happens to be the ne
12.
▲
by
Peristarkawan
15y ago
Yes, Python's super is more like Dylan's next-method than, say, C#'s super.