Skip to content

Commit 99f8a60

Browse files
authored
Merge pull request faif#309 from gyermolenko/py3only2
Remove py2 compatibility-related stuff
2 parents 8fba959 + 6b63634 commit 99f8a60

38 files changed

+88
-141
lines changed

patterns/behavioral/catalog.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
A class that uses different static function depending of a parameter passed in
@@ -9,7 +8,7 @@
98
__author__ = "Ibrahim Diop <ibrahim@sikilabs.com>"
109

1110

12-
class Catalog(object):
11+
class Catalog:
1312
"""catalog of multiple static methods that are executed depending on an init
1413
1514
parameter
@@ -45,7 +44,7 @@ def main_method(self):
4544

4645

4746
# Alternative implementation for different levels of methods
48-
class CatalogInstance(object):
47+
class CatalogInstance:
4948

5049
"""catalog of multiple methods that are executed depending on an init
5150
@@ -77,7 +76,7 @@ def main_method(self):
7776
self._instance_method_choices[self.param].__get__(self)()
7877

7978

80-
class CatalogClass(object):
79+
class CatalogClass:
8180

8281
"""catalog of multiple class methods that are executed depending on an init
8382
@@ -112,7 +111,7 @@ def main_method(self):
112111
self._class_method_choices[self.param].__get__(None, self.__class__)()
113112

114113

115-
class CatalogStatic(object):
114+
class CatalogStatic:
116115

117116
"""catalog of multiple static methods that are executed depending on an init
118117

patterns/behavioral/chain_of_responsibility.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
*What is this pattern about?

patterns/behavioral/chaining_method.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

4-
from __future__ import print_function
53

6-
7-
class Person(object):
4+
class Person:
85
def __init__(self, name, action):
96
self.name = name
107
self.action = action
@@ -14,7 +11,7 @@ def do_action(self):
1411
return self.action
1512

1613

17-
class Action(object):
14+
class Action:
1815
def __init__(self, name):
1916
self.name = name
2017

patterns/behavioral/command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
*TL;DR
@@ -10,11 +9,10 @@
109
https://docs.djangoproject.com/en/2.1/ref/request-response/#httprequest-objects
1110
"""
1211

13-
from __future__ import print_function
1412
import os
1513

1614

17-
class MoveFileCommand(object):
15+
class MoveFileCommand:
1816
def __init__(self, src, dest):
1917
self.src = src
2018
self.dest = dest
@@ -26,7 +24,7 @@ def undo(self):
2624
self.rename(self.dest, self.src)
2725

2826
def rename(self, src, dest):
29-
print(u"renaming %s to %s" % (src, dest))
27+
print("renaming {} to {}".format(src, dest))
3028
os.rename(src, dest)
3129

3230

patterns/behavioral/iterator.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/
@@ -9,8 +8,6 @@
98
Traverses a container and accesses the container's elements.
109
"""
1110

12-
from __future__ import print_function
13-
1411

1512
def count_to(count):
1613
"""Counts by word numbers, up to a maximum of five"""

patterns/behavioral/mediator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
https://www.djangospin.com/design-patterns-python/mediator/
@@ -12,14 +11,14 @@
1211
"""
1312

1413

15-
class ChatRoom(object):
14+
class ChatRoom:
1615
"""Mediator class"""
1716

1817
def display_message(self, user, message):
1918
print("[{} says]: {}".format(user, message))
2019

2120

22-
class User(object):
21+
class User:
2322
"""A class whose instances want to interact with each other"""
2423

2524
def __init__(self, name):

patterns/behavioral/memento.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
http://code.activestate.com/recipes/413838-memento-closure/
@@ -22,7 +21,7 @@ def restore():
2221
return restore
2322

2423

25-
class Transaction(object):
24+
class Transaction:
2625
"""A transaction guard.
2726
2827
This is, in fact, just syntactic sugar around a memento closure.
@@ -44,7 +43,7 @@ def rollback(self):
4443
a_state()
4544

4645

47-
class Transactional(object):
46+
class Transactional:
4847
"""Adds transactional semantics to methods. Methods decorated with
4948
5049
@Transactional will rollback to entry-state upon exceptions.
@@ -65,7 +64,7 @@ def transaction(*args, **kwargs):
6564
return transaction
6665

6766

68-
class NumObj(object):
67+
class NumObj:
6968
def __init__(self, value):
7069
self.value = value
7170

patterns/behavioral/observer.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
"""
54
http://code.activestate.com/recipes/131499-observer-pattern/
@@ -12,10 +11,8 @@
1211
Flask Signals: http://flask.pocoo.org/docs/1.0/signals/
1312
"""
1413

15-
from __future__ import print_function
1614

17-
18-
class Subject(object):
15+
class Subject:
1916
def __init__(self):
2017
self._observers = []
2118

@@ -35,7 +32,6 @@ def notify(self, modifier=None):
3532
observer.update(self)
3633

3734

38-
# Example usage
3935
class Data(Subject):
4036
def __init__(self, name=''):
4137
Subject.__init__(self)
@@ -54,15 +50,14 @@ def data(self, value):
5450

5551
class HexViewer:
5652
def update(self, subject):
57-
print(u'HexViewer: Subject %s has data 0x%x' % (subject.name, subject.data))
53+
print('HexViewer: Subject {} has data 0x{:x}'.format(subject.name, subject.data))
5854

5955

6056
class DecimalViewer:
6157
def update(self, subject):
62-
print(u'DecimalViewer: Subject %s has data %d' % (subject.name, subject.data))
58+
print('DecimalViewer: Subject %s has data %d' % (subject.name, subject.data))
6359

6460

65-
# Example usage...
6661
def main():
6762
"""
6863
>>> data1 = Data('Data 1')

patterns/behavioral/publish_subscribe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
2+
33
"""
44
Reference:
55
http://www.slideshare.net/ishraqabd/publish-subscribe-model-overview-13368808

patterns/behavioral/registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43

54
class RegistryHolder(type):

0 commit comments

Comments
 (0)