54 ms·
Admittedly, I generally write procedural and/or functional python code... but how is: class CPUInfo(dict): def __init__(self, *args): dict.__init__(self,
by e12e 12y ago
Admittedly, I generally write procedural and/or functional python code... but how is:
class CPUInfo(dict):
def __init__(self, *args):
dict.__init__(self, args)
def __getitem__(self, key):
val = dict.__getitem__(self, key)
return val
def __setitem__(self, key, val):
dict.__setitem__(self, key, val)
Different from:
class CPUInfo(dict):
pass
Doesn't the overrides behave just like dict does?
- aeikenberry 12y agoI was going to ask the same thing.
- bliti 12y agoAuthor probably has future plans for the class. I've seen people write classes like that to later do overloading. Others write out the methods to sort of document that those are the ones they are using. I know it might not be one's cup of tea, but let he who writes perfect code every time push to production without testing it first.
- e12e 12y agoWell, it's nice to see my intuition was right. Seems a little redundant as documentation - at least for classes in the standard lib. And I'd prefer the diff from "pass" to "added overloaded method" rather than "changed standard method". I think.