Skip to content

Commit

Permalink
Remove all class C(object): syntax, no longer need to inherit from ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
ptmcg committed Jul 18, 2022
1 parent 0c11141 commit da378b1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions 04_Object_Oriented_Python/bound_and_unbound_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def f(a, b):
'''a function f with two arguments'''
print(a, b)
class C(object):
class C:
name = f
x = C()

Expand All @@ -18,15 +18,15 @@ def add(addend, _augend=augend):
return add

def make_adder_as_bound_method(augend):
class Adder(object):
class Adder:
def __init__(self, augend):
self.augend = augend
def add(self, addend):
return addend+self.augend
return Adder(augend).add

def make_adder_as_callable_instance(augend):
class Adder(object):
class Adder:
def __init__(self, augend):
self.augend = augend
def __call__(self, addend):
Expand Down
4 changes: 2 additions & 2 deletions 04_Object_Oriented_Python/class_level_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# staticmethod example
class AClass(object):
class AClass:
def astatic():
print('a static method')
astatic = staticmethod(astatic)
Expand All @@ -8,7 +8,7 @@ def astatic():
an_instance.astatic() # prints: a static method

# classmethod example
class ABase(object):
class ABase:
def aclassmet(cls):
print('a class method for', cls.__name__)
aclassmet = classmethod(aclassmet)
Expand Down
2 changes: 1 addition & 1 deletion 04_Object_Oriented_Python/per_instance_methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def fake_get_item(idx):
return idx

class MyClass(object):
class MyClass:
pass

n = MyClass()
Expand Down
6 changes: 3 additions & 3 deletions 04_Object_Oriented_Python/properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

class Rectangle(object):
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
Expand All @@ -13,7 +13,7 @@ def get_area(self):
print(r.area) # <- property, no ()'s

# property decorator
class Rectangle(object):
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
Expand All @@ -27,7 +27,7 @@ def area(self):
print(r.area)


class Rectangle(object):
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
Expand Down
4 changes: 2 additions & 2 deletions 04_Object_Oriented_Python/properties_and_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# method is overridden in derived class (property is
# defined using the base class method, and not resolved
# to the derived class method)
class B(object):
class B:
def f(self):
return 23
g = property(f)
Expand All @@ -15,7 +15,7 @@ def f(self):
# call subclass method from property by binding property
# to method that calls self.f(), to resolve to the derived
# class's method
class B(object):
class B:
def f(self):
return 23
def _f_getter(self):
Expand Down
2 changes: 1 addition & 1 deletion 04_Object_Oriented_Python/simple_bunch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class SimpleBunch(object):
class SimpleBunch:
def __init__(self, **fields):
self._dict__ = fields

Expand Down
2 changes: 1 addition & 1 deletion 04_Object_Oriented_Python/slots_rectangle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rectangle(object):
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
Expand Down
2 changes: 1 addition & 1 deletion 05_Exceptions/tag_context_manager_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# if _normal_exit:
# _manager.__exit__(None, None, None)

class tag(object):
class tag:
def __init__(self, tagname):
self.tagname = tagname
def __enter__(self):
Expand Down

0 comments on commit da378b1

Please sign in to comment.