Skip to content

Commit b22b7ac

Browse files
author
Arie
committed
Switch to new style class declaration
Also fixed imports and docs.
1 parent af654f6 commit b22b7ac

File tree

9 files changed

+41
-39
lines changed

9 files changed

+41
-39
lines changed

behavioral/catalog.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
__gist__ = "<https://gist.github.com/diopib/7679559>"
99

1010

11-
class Catalog():
11+
class Catalog(object):
12+
"""catalog of multiple static methods that are executed depending on an init
1213
13-
"""
14-
catalog of multiple static methods that are executed depending on an init
1514
parameter
1615
"""
1716

@@ -38,18 +37,18 @@ def _static_method_2():
3837
print("executed method 2!")
3938

4039
def main_method(self):
41-
"""
42-
will execute either _static_method_1 or _static_method_2
40+
"""will execute either _static_method_1 or _static_method_2
41+
4342
depending on self.param value
4443
"""
4544
self._static_method_choices[self.param]()
4645

4746

4847
# Alternative implementation for different levels of methods
49-
class CatalogInstance:
48+
class CatalogInstance(object):
49+
50+
"""catalog of multiple methods that are executed depending on an init
5051
51-
"""
52-
catalog of multiple methods that are executed depending on an init
5352
parameter
5453
"""
5554

@@ -72,17 +71,17 @@ def _instance_method_2(self):
7271
'param_value_2': _instance_method_2}
7372

7473
def main_method(self):
75-
"""
76-
will execute either _instance_method_1 or _instance_method_2
74+
"""will execute either _instance_method_1 or _instance_method_2
75+
7776
depending on self.param value
7877
"""
7978
self._instance_method_choices[self.param].__get__(self)()
8079

8180

82-
class CatalogClass:
81+
class CatalogClass(object):
82+
83+
"""catalog of multiple class methods that are executed depending on an init
8384
84-
"""
85-
catalog of multiple class methods that are executed depending on an init
8685
parameter
8786
"""
8887

@@ -108,17 +107,17 @@ def _class_method_2(cls):
108107
'param_value_2': _class_method_2}
109108

110109
def main_method(self):
111-
"""
112-
will execute either _class_method_1 or _class_method_2
110+
"""will execute either _class_method_1 or _class_method_2
111+
113112
depending on self.param value
114113
"""
115114
self._class_method_choices[self.param].__get__(None, self.__class__)()
116115

117116

118-
class CatalogStatic:
117+
class CatalogStatic(object):
118+
119+
"""catalog of multiple static methods that are executed depending on an init
119120
120-
"""
121-
catalog of multiple static methods that are executed depending on an init
122121
parameter
123122
"""
124123

@@ -141,8 +140,8 @@ def _static_method_2():
141140
'param_value_2': _static_method_2}
142141

143142
def main_method(self):
144-
"""
145-
will execute either _static_method_1 or _static_method_2
143+
"""will execute either _static_method_1 or _static_method_2
144+
146145
depending on self.param value
147146
"""
148147
self._static_method_choices[self.param].__get__(None, self.__class__)()

behavioral/chain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# -*- coding: utf-8 -*-
33
"""http://www.dabeaz.com/coroutines/"""
44

5-
import time
5+
from contextlib import contextmanager
66
import os
77
import sys
8-
from contextlib import contextmanager
8+
import time
9+
910

11+
class Handler(object):
1012

11-
class Handler:
12-
1313
def __init__(self, successor=None):
1414
self._successor = successor
1515

@@ -53,7 +53,7 @@ def _handle(self, request):
5353
return True
5454

5555

56-
class Client:
56+
class Client(object):
5757

5858
def __init__(self):
5959
self.handler = ConcreteHandler1(

behavioral/memento.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# -*- coding: utf-8 -*-
33
"""http://code.activestate.com/recipes/413838-memento-closure/"""
44

5-
from copy import copy, deepcopy
5+
from copy import copy
6+
from copy import deepcopy
67

78

89
def memento(obj, deep=False):
@@ -15,8 +16,9 @@ def restore():
1516
return restore
1617

1718

18-
class Transaction:
19+
class Transaction(object):
1920
"""A transaction guard.
21+
2022
This is, in fact, just syntactic sugar around a memento closure.
2123
"""
2224
deep = False
@@ -37,6 +39,7 @@ def rollback(self):
3739

3840
class Transactional(object):
3941
"""Adds transactional semantics to methods. Methods decorated with
42+
4043
@Transactional will rollback to entry-state upon exceptions.
4144
"""
4245

behavioral/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_registry(cls):
2020
return dict(cls.REGISTRY)
2121

2222

23-
class BaseRegisteredClass:
23+
class BaseRegisteredClass(object):
2424
__metaclass__ = RegistryHolder
2525
"""
2626
Any class that will inherits from BaseRegisteredClass will be included

creational/abstract_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import random
99

1010

11-
class PetShop:
11+
class PetShop(object):
1212

1313
"""A pet shop"""
1414

@@ -28,7 +28,7 @@ def show_pet(self):
2828

2929
# Stuff that our factory makes
3030

31-
class Dog:
31+
class Dog(object):
3232

3333
def speak(self):
3434
return "woof"
@@ -37,7 +37,7 @@ def __str__(self):
3737
return "Dog"
3838

3939

40-
class Cat:
40+
class Cat(object):
4141

4242
def speak(self):
4343
return "meow"
@@ -48,7 +48,7 @@ def __str__(self):
4848

4949
# Factory classes
5050

51-
class DogFactory:
51+
class DogFactory(object):
5252

5353
def get_pet(self):
5454
return Dog()
@@ -57,7 +57,7 @@ def get_food(self):
5757
return "dog food"
5858

5959

60-
class CatFactory:
60+
class CatFactory(object):
6161

6262
def get_pet(self):
6363
return Cat()

creational/borg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44

5-
class Borg:
5+
class Borg(object):
66
__shared_state = {}
77

88
def __init__(self):

creational/factory_method.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/"""
55

66

7-
class GreekGetter:
7+
class GreekGetter(object):
88

99
"""A simple localizer a la gettext"""
1010

@@ -16,7 +16,7 @@ def get(self, msgid):
1616
return self.trans.get(msgid, str(msgid))
1717

1818

19-
class EnglishGetter:
19+
class EnglishGetter(object):
2020

2121
"""Simply echoes the msg ids"""
2222

creational/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88

9-
class QueueObject():
9+
class QueueObject(object):
1010

1111
def __init__(self, queue, auto_get=False):
1212
self._queue = queue

creational/prototype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import copy
55

66

7-
class Prototype:
7+
class Prototype(object):
88

99
value = 'default'
1010

@@ -15,7 +15,7 @@ def clone(self, **attrs):
1515
return obj
1616

1717

18-
class PrototypeDispatcher:
18+
class PrototypeDispatcher(object):
1919

2020
def __init__(self):
2121
self._objects = {}

0 commit comments

Comments
 (0)