Skip to content

Commit b14ed96

Browse files
committed
Removed usages and examples of subclassing from (object) from py2
1 parent 0b172a4 commit b14ed96

File tree

23 files changed

+106
-94
lines changed

23 files changed

+106
-94
lines changed

source/examples/context_managers/context_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Demo of a contextmanager
22

33

4-
class Context(object):
4+
class Context:
55
"""
66
from Doug Hellmann, PyMOTW
77
https://pymotw.com/3/contextlib/#module-contextlib

source/examples/metaprogramming/my_solution.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# original class made as simple as possible
2-
class TestClass(object):
2+
3+
class TestClass:
34

45
engine = None
56

@@ -22,9 +23,9 @@ def get_privilege(self):
2223
return self.data, TestClass.engine
2324

2425

25-
class MyClass(object):
26-
27-
class __MyClass(object):
26+
class MyClass:
27+
28+
class __MyClass:
2829
def __init__(self, db_config):
2930
self.db_config = db_config
3031
self.data = None

source/examples/metaprogramming/start_class.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sqlalchemy
22

3-
4-
class AccessTable(object):
3+
class AccessTable:
54

65
engine = None
76

@@ -49,7 +48,7 @@ def get_privilege(self, name, group):
4948
access = self.metadata.tables['access']
5049
select = sqlalchemy.select([access.c.privilege]).where(sqlalchemy.sql.and_(access.c.name == name,
5150
access.c.group == group))
52-
51+
5352
# TODO handle result including case where it doesn't find any records
5453
_result = engine.execute(select)
5554
return 'readwrite'

source/examples/multiple_inheritance/diamond.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"""
3737

3838

39-
class A(object):
39+
class A:
4040
def do_your_stuff(self):
4141
print("doing A's stuff")
4242

source/examples/multiple_inheritance/diamond_super.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"""
3535

3636

37-
class A(object):
37+
class A:
3838
def do_your_stuff(self):
3939
print("doing A's stuff")
4040

source/examples/multiple_inheritance/mro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33

4-
class A(object):
4+
class A:
55
def my_method(self):
66
print("called A")
77

source/examples/multiple_inheritance/super_test.ipynb

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 3,
41+
"execution_count": 2,
4242
"metadata": {},
4343
"outputs": [
4444
{
@@ -74,7 +74,7 @@
7474
"python3 fills these in for you at run time, but in python2, you needed to specify them:\n",
7575
"\n",
7676
"```\n",
77-
"class A(object):\n",
77+
"class A:\n",
7878
" def __init__(self):\n",
7979
" super(A, self).__init__()\n",
8080
"```\n",
@@ -90,7 +90,7 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 4,
93+
"execution_count": 3,
9494
"metadata": {},
9595
"outputs": [
9696
{
@@ -115,7 +115,7 @@
115115
},
116116
{
117117
"cell_type": "code",
118-
"execution_count": 5,
118+
"execution_count": 4,
119119
"metadata": {},
120120
"outputs": [
121121
{
@@ -132,7 +132,7 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": 7,
135+
"execution_count": 5,
136136
"metadata": {},
137137
"outputs": [
138138
{
@@ -142,7 +142,7 @@
142142
"traceback": [
143143
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
144144
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
145-
"\u001b[0;32m<ipython-input-7-89cc2a7e6da3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
145+
"\u001b[0;32m<ipython-input-5-f817bbf8c6b4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
146146
"\u001b[0;31mTypeError\u001b[0m: super(type, obj): obj must be an instance or subtype of type"
147147
]
148148
}
@@ -160,7 +160,7 @@
160160
},
161161
{
162162
"cell_type": "code",
163-
"execution_count": 8,
163+
"execution_count": 6,
164164
"metadata": {},
165165
"outputs": [
166166
{
@@ -178,7 +178,7 @@
178178
},
179179
{
180180
"cell_type": "code",
181-
"execution_count": 9,
181+
"execution_count": 7,
182182
"metadata": {},
183183
"outputs": [
184184
{
@@ -196,7 +196,7 @@
196196
},
197197
{
198198
"cell_type": "code",
199-
"execution_count": 10,
199+
"execution_count": 8,
200200
"metadata": {},
201201
"outputs": [
202202
{
@@ -220,10 +220,8 @@
220220
},
221221
{
222222
"cell_type": "code",
223-
"execution_count": 11,
224-
"metadata": {
225-
"collapsed": true
226-
},
223+
"execution_count": 9,
224+
"metadata": {},
227225
"outputs": [],
228226
"source": [
229227
"# without super()\n",
@@ -245,7 +243,7 @@
245243
},
246244
{
247245
"cell_type": "code",
248-
"execution_count": 12,
246+
"execution_count": 10,
249247
"metadata": {},
250248
"outputs": [
251249
{
@@ -281,7 +279,7 @@
281279
},
282280
{
283281
"cell_type": "code",
284-
"execution_count": 13,
282+
"execution_count": 11,
285283
"metadata": {},
286284
"outputs": [],
287285
"source": [
@@ -301,7 +299,7 @@
301299
},
302300
{
303301
"cell_type": "code",
304-
"execution_count": 14,
302+
"execution_count": 12,
305303
"metadata": {},
306304
"outputs": [
307305
{
@@ -340,7 +338,7 @@
340338
},
341339
{
342340
"cell_type": "code",
343-
"execution_count": 16,
341+
"execution_count": 13,
344342
"metadata": {},
345343
"outputs": [],
346344
"source": [
@@ -365,7 +363,7 @@
365363
},
366364
{
367365
"cell_type": "code",
368-
"execution_count": 17,
366+
"execution_count": 14,
369367
"metadata": {},
370368
"outputs": [
371369
{
@@ -396,10 +394,8 @@
396394
},
397395
{
398396
"cell_type": "code",
399-
"execution_count": 18,
400-
"metadata": {
401-
"collapsed": true
402-
},
397+
"execution_count": 15,
398+
"metadata": {},
403399
"outputs": [],
404400
"source": [
405401
"class Base():\n",
@@ -424,7 +420,7 @@
424420
},
425421
{
426422
"cell_type": "code",
427-
"execution_count": 19,
423+
"execution_count": 16,
428424
"metadata": {},
429425
"outputs": [
430426
{
@@ -451,7 +447,7 @@
451447
},
452448
{
453449
"cell_type": "code",
454-
"execution_count": 20,
450+
"execution_count": 17,
455451
"metadata": {},
456452
"outputs": [
457453
{
@@ -460,7 +456,7 @@
460456
"(__main__.A, __main__.Base, object)"
461457
]
462458
},
463-
"execution_count": 20,
459+
"execution_count": 17,
464460
"metadata": {},
465461
"output_type": "execute_result"
466462
}
@@ -480,7 +476,7 @@
480476
},
481477
{
482478
"cell_type": "code",
483-
"execution_count": 21,
479+
"execution_count": 18,
484480
"metadata": {},
485481
"outputs": [],
486482
"source": [
@@ -507,7 +503,7 @@
507503
},
508504
{
509505
"cell_type": "code",
510-
"execution_count": 22,
506+
"execution_count": 19,
511507
"metadata": {},
512508
"outputs": [
513509
{
@@ -540,9 +536,14 @@
540536
{
541537
"cell_type": "code",
542538
"execution_count": null,
543-
"metadata": {
544-
"collapsed": true
545-
},
539+
"metadata": {},
540+
"outputs": [],
541+
"source": []
542+
},
543+
{
544+
"cell_type": "code",
545+
"execution_count": null,
546+
"metadata": {},
546547
"outputs": [],
547548
"source": []
548549
}
@@ -563,7 +564,7 @@
563564
"name": "python",
564565
"nbconvert_exporter": "python",
565566
"pygments_lexer": "ipython3",
566-
"version": "3.6.2"
567+
"version": "3.8.6"
567568
}
568569
},
569570
"nbformat": 4,

source/examples/multiple_inheritance/super_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self):
5050
# specify them:
5151
#
5252
# ```
53-
# class A(object):
53+
# class A:
5454
# def __init__(self):
5555
# super(A, self).__init__()
5656
# ```

source/examples/nosql/address_book_model.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python
22

33
"""
4-
sample data for NOSQL examples
4+
Sample data for NOSQL examples
55
66
This version has a not completely-trival data model
77
"""
88

99

10-
class Person(object):
10+
class Person:
1111
"""
1212
class to represent an individual person
1313
"""
@@ -43,7 +43,7 @@ def __repr__(self):
4343
return self.__str__()
4444

4545

46-
class Address(object):
46+
class Address:
4747
"""
4848
class that represents an address
4949
"""
@@ -70,11 +70,11 @@ def __str__(self):
7070
return msg
7171

7272

73-
class Household(object):
73+
class Household:
7474
"""
7575
Class that represents a Household.
7676
77-
A household has one or more people, and a Location
77+
A household has one or more people, and an address
7878
"""
7979

8080
def __init__(self,
@@ -97,7 +97,7 @@ def __repr__(self):
9797
return self.__str__()
9898

9999

100-
class Business(Household):
100+
class Business:
101101
"""
102102
Class that represents a Business
103103
@@ -108,7 +108,7 @@ class Business(Household):
108108
pass
109109

110110

111-
class AddressBook(object):
111+
class AddressBook:
112112
"""
113113
And address book -- has people, households, businesses.
114114

source/examples/nosql/address_book_mongo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""
4-
sample data for NOSQL examples
4+
Sample data for NOSQL examples
55
66
This version uses mongoDB to store the data.
77
@@ -168,7 +168,7 @@ class Business(Household):
168168
pass
169169

170170

171-
class AddressBook(object):
171+
class AddressBook:
172172
"""
173173
An address book -- has people, households, businesses.
174174
@@ -223,7 +223,8 @@ def find_people(self, name=''):
223223
Find all the people with name in their name somewhere
224224
"""
225225
# fixme -- can this query be combined?
226-
# like this: db.inventory.find( { $or: [ { qty: { $lt: 20 } }, { sale: true } ] } )
226+
# like this:
227+
# db.inventory.find( { $or: [ { qty: { $lt: 20 } }, { sale: true } ] } )
227228

228229
cursor = self.people.find({"first_name": {'$regex': '.*' + name + '.*',
229230
'$options': 'i'}})

0 commit comments

Comments
 (0)