Conversation
Lib/ipaddress.py
Outdated
There was a problem hiding this comment.
What is faster, _BaseNetwork.__init__() or super().__init__()?
There was a problem hiding this comment.
In my initial patch I changed this to the super().__init__() on purpose from the version where the base class is mentioned explicitly. Not using the super() version here makes it harder to write subclasses for those classes. Also, I personally think it's better style to use super().
I have not measured it but I don't think that this is a significant speed improvement.
There was a problem hiding this comment.
Not using the
super()version here makes it harder to write subclasses for those classes.
Simple subclass is OK without super(). It helps only complicated subclassing like:
class A(IPv4Network):
def __init__(self, address):
super().__init__(address)
class B(_BaseNetwork):
def __init__(self, address)
super().__init__(address)
class C(A, B):
def __init__(self, address):
super().__init__(address)In this case, if we don't use super() in IPv4Network, __init__ is called for C -> A -> IPv4Network -> _BaseNetwork (B is skipped)
if we use super(), C -> A -> IPv4Network -> B -> _BaseNetwork.
But note that _BaseNetwork is private class.
Not using super() here doesn't make write subclass of IPv4Network harder.
Also, I personally think it's better style to use
super().
I'm +0.1 on super in general.
I have not measured it but I don't think that this is a significant speed improvement.
It seems 3% slowdown.
$ ./python -m perf timeit -s 'from ipaddress import IPv4Network' 'IPv4Network("10.10.1.0/24")'
...
Mean +- std dev: [legacy] 8.96 us +- 0.09 us -> [super] 9.23 us +- 0.07 us: 1.03x slower (+3%)
I don't have any strong opinion here.
There was a problem hiding this comment.
Now there is no __init__ call.
Lib/ipaddress.py
Outdated
There was a problem hiding this comment.
This seems like a new property as per current docs at https://docs.python.org/3.8/library/ipaddress.html#ipaddress.IPv4Interface . Should this be documented?
|
@methane This might increase the scope of the PR but there are functions where Explanation from Serhiy on the optimization : https://bugs.python.org/issue25430#msg294442 |
Patch by Moritz Sichert.
https://bugs.python.org/issue27860