Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update super usage #1280

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/traits_user_manual/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ However, in cases where this strategy is insufficient, use the following pattern
to override __getstate__() to remove items that should not be persisted::

def __getstate__ ( self ):
state = super( XXX, self ).__getstate__()
state = super().__getstate__()

for key in [ 'foo', 'bar' ]:
if key in state:
Expand Down Expand Up @@ -1309,8 +1309,8 @@ ensure that their internal object state remains consistent and up to date.
pickling time. If this key is not present when unpickling, the HasTraits
__setstate__() method falls back to a compatibility mode and may not restore
the state correctly. For the same reason, if you're overriding
__getstate__(), you should be careful to make the appropriate ``super(...,
self).__getstate__()`` call.
__getstate__(), you should be careful to make the appropriate
``super().__getstate__()`` call.

.. index:: __setstate__(); overriding

Expand Down
2 changes: 1 addition & 1 deletion docs/source/traits_user_manual/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Here's an example of subclassing a predefined trait class::
info_text = 'an odd integer'

def validate ( self, object, name, value ):
value = super(OddInt, self).validate(object, name, value)
value = super().validate(object, name, value)
if (value % 2) == 1:
return value

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/doc_examples/examples/trait_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OddInt(BaseInt):
info_text = "an odd integer"

def validate(self, object, name, value):
value = super(OddInt, self).validate(object, name, value)
value = super().validate(object, name, value)
if (value % 2) == 1:
return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DataBase(HasTraits):
not be persisted::

def __getstate__(self):
state = super(XXX, self).__getstate__()
state = super().__getstate__()

for key in [ 'foo', 'bar' ]:
if key in state:
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/traits_4.0/trait_types/new_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class RandInt(TraitType):

# Define the type's constructor:
def __init__(self, low=1, high=10, **metadata):
super(RandInt, self).__init__(**metadata)
super().__init__(**metadata)
self.low = int(low)
self.high = int(high)

Expand Down
4 changes: 2 additions & 2 deletions examples/tutorials/traits_4.0/trait_types/trait_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OddInt(BaseInt):
info_text = 'an odd integer'

def validate(self, object, name, value):
value = super(OddInt, self).validate(object, name, value)
value = super().validate(object, name, value)
if (value % 2) == 1:
return value

Expand Down Expand Up @@ -112,7 +112,7 @@ class OddInt(BaseInt):
info_text = "an odd integer"

def validate(self, object, name, value):
value = super(OddInt, self).validate(object, name, value)
value = super().validate(object, name, value)
if (value % 2) == 1:
return value

Expand Down
2 changes: 1 addition & 1 deletion traits/adaptation/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class Adapter(HasTraits):

def __init__(self, adaptee, **traits):
traits["adaptee"] = adaptee
super(Adapter, self).__init__(**traits)
super().__init__(**traits)

adaptee = Any
2 changes: 1 addition & 1 deletion traits/etsconfig/tests/test_etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def setUp(self):
def run(self, result=None):
# Extend TestCase.run to use a temporary home directory.
with temporary_home_directory():
super(ETSConfigTestCase, self).run(result)
super().run(result)

###########################################################################
# 'ETSConfigTestCase' interface.
Expand Down
4 changes: 2 additions & 2 deletions traits/has_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def __getstate__(self):
not be persisted::

def __getstate__(self):
state = super(X,self).__getstate__()
state = super().__getstate__()
for key in ['foo', 'bar']:
if key in state:
del state[key]
Expand Down Expand Up @@ -3438,7 +3438,7 @@ def __init__(self, **traits):
"{}.".format(", ".join(sorted(missing_required_traits)))
)

super(HasRequiredTraits, self).__init__(**traits)
super().__init__(**traits)


class HasPrivateTraits(HasTraits):
Expand Down
2 changes: 1 addition & 1 deletion traits/testing/unittest_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def __init__(self, **traits):
)
warnings.warn(message, DeprecationWarning, stacklevel=2)
traits["trait_name"] = value
super(_TraitsChangeCollector, self).__init__(**traits)
super().__init__(**traits)

def start_collecting(self):
self.obj.on_trait_change(self._event_handler, self.trait_name)
Expand Down
4 changes: 2 additions & 2 deletions traits/tests/test_copy_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CopyTraitsBase(unittest.TestCase):
__test__ = False

def setUp(self):
super(CopyTraitsBase, self).setUp()
super().setUp()
self.shared = Shared(s="shared")
self.foo = Foo(shared=self.shared, s="foo")
self.bar = Bar(shared=self.shared, foo=self.foo, s="bar")
Expand All @@ -63,7 +63,7 @@ class TestCopyTraitsSetup(CopyTraitsBase):
__test__ = True

def setUp(self):
super(TestCopyTraitsSetup, self).setUp()
super().setUp()

def test_setup(self):
self.assertIs(self.foo, self.bar.foo)
Expand Down
2 changes: 1 addition & 1 deletion traits/tests/test_extended_notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, **traits):
for listener in fail_listeners:
self._on_trait_change(listener, "fail", dispatch="extended")

super(ExtendedNotifiers, self).__init__(**traits)
super().__init__(**traits)

ok = Float
fail = Float
Expand Down
2 changes: 1 addition & 1 deletion traits/tests/test_pickle_validated_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class C(HasTraits):

# And we must initialize it to something non-trivial
def __init__(self):
super(C, self).__init__()
super().__init__()
self.a = {1: [2, 3]}


Expand Down
2 changes: 1 addition & 1 deletion traits/tests/test_python_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class Model(HasTraits):
def __init__(self):
super(Model, self).__init__()
super().__init__()
self._value = 0

@property
Expand Down
2 changes: 1 addition & 1 deletion traits/tests/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class UnionAllowStr(Union):
def validate(self, obj, name, value):
if isinstance(value, str):
return value
return super(UnionAllowStr, self).validate(obj, name, value)
return super().validate(obj, name, value)

class TestClass(HasTraits):
s = UnionAllowStr(Int, Float)
Expand Down
2 changes: 1 addition & 1 deletion traits/trait_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def validate(self, object, name, value):
self.error(object, name, value)

def info(self):
return super(TraitPrefixMap, self).info() + " (or any unique prefix)"
return super().info() + " (or any unique prefix)"


class TraitCompound(TraitHandler):
Expand Down
10 changes: 5 additions & 5 deletions traits/trait_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
self.coerce = coerce
self.casting = casting

super(AbstractArray, self).__init__(value, **metadata)
super().__init__(value, **metadata)

def validate(self, object, name, value):
""" Validates that the value is a valid array.
Expand Down Expand Up @@ -334,7 +334,7 @@ def __init__(
casting="unsafe",
**metadata
):
super(Array, self).__init__(
super().__init__(
dtype,
shape,
value,
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(
casting="unsafe",
**metadata
):
super(CArray, self).__init__(
super().__init__(
dtype,
shape,
value,
Expand All @@ -424,12 +424,12 @@ class ArrayOrNone(CArray):
def __init__(self, *args, **metadata):
# Normally use object identity to detect array values changing:
metadata.setdefault("comparison_mode", ComparisonMode.identity)
super(ArrayOrNone, self).__init__(*args, **metadata)
super().__init__(*args, **metadata)

def validate(self, object, name, value):
if value is None:
return value
return super(ArrayOrNone, self).validate(object, name, value)
return super().validate(object, name, value)

def get_default_value(self):
dv = self.default_value
Expand Down
Loading