Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c296652

Browse files
committed
Fixed Python 2.6 warning with traitlets object.__new__.
In Python 2.6 a warning is given if object.__new__ is called with anything more than first cls argument. We are using super so we needed a way to see of the __new__ method about to be called is object.__new__.
1 parent 74bb15f commit c296652

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

IPython/utils/traitlets.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,13 @@ class HasTraitlets(object):
342342
__metaclass__ = MetaHasTraitlets
343343

344344
def __new__(cls, *args, **kw):
345-
inst = super(HasTraitlets, cls).__new__(cls, *args, **kw)
345+
# This is needed because in Python 2.6 object.__new__ only accepts
346+
# the cls argument.
347+
new_meth = super(HasTraitlets, cls).__new__
348+
if new_meth is object.__new__:
349+
inst = new_meth(cls)
350+
else:
351+
inst = new_meth(cls, *args, **kw)
346352
inst._traitlet_values = {}
347353
inst._traitlet_notifiers = {}
348354
# Here we tell all the TraitletType instances to set their default

0 commit comments

Comments
 (0)