Skip to content
Open
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 Behavioral/chain_of_responsibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConcreteHandlerA(Handler):

def handle_request(self, request):
if 0 <= request < 10:
print("%s process %s" % (self.__class__.__name__, request))
print(f"{self.__class__.__name__} process {request}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteHandlerA.handle_request refactored with the following changes:

else:
self.successor.handle_request(request)

Expand All @@ -56,7 +56,7 @@ class ConcreteHandlerB(Handler):

def handle_request(self, request):
if 10 <= request < 20:
print("%s process %s" % (self.__class__.__name__, request))
print(f"{self.__class__.__name__} process {request}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteHandlerB.handle_request refactored with the following changes:

else:
self.successor.handle_request(request)

Expand All @@ -70,7 +70,7 @@ class ConcreteHandlerC(Handler):

def handle_request(self, request):
if 20 <= request < 30:
print("%s process %s" % (self.__class__.__name__, request))
print(f"{self.__class__.__name__} process {request}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteHandlerC.handle_request refactored with the following changes:

else:
self.successor.handle_request(request)

Expand Down
3 changes: 1 addition & 2 deletions Behavioral/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def output(self, value):
if __name__ == '__main__':
context = Context("in", "out")

l = []
l.append(TerminalExpression())
l = [TerminalExpression()]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 82-83 refactored with the following changes:

l.append(TerminalExpression())
l.append(NoterminalExpression())

Expand Down
9 changes: 4 additions & 5 deletions Behavioral/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ def __iter__(self):


def __next__(self):
if self.i < self.n:
i = self.i
self.i += 1
return i
else:
if self.i >= self.n:
raise StopIteration()
i = self.i
self.i += 1
return i
Comment on lines -83 to +87
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YRange.__next__ refactored with the following changes:



if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion Behavioral/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, subject, name):

def update(self):
self.objserver_staus = self.subject.status
print("the observer: %s status change to %s" % (self.name , self.objserver_staus))
print(f"the observer: {self.name} status change to {self.objserver_staus}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteObserver.update refactored with the following changes:



if __name__ == '__main__':
Expand Down
20 changes: 12 additions & 8 deletions Behavioral/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class ConcreteVisitor1(Visitor):
"""

def visitor_concrete_element_a(self, concrete_element_a):
print("%s visit %s" % (self.__class__.__name__,
concrete_element_a.__class__.__name__))
print(
f"{self.__class__.__name__} visit {concrete_element_a.__class__.__name__}"
)
Comment on lines -40 to +42
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteVisitor1.visitor_concrete_element_a refactored with the following changes:


def visitor_concrete_element_b(self, concrete_element_b):
print("%s visit %s" % (self.__class__.__name__,
concrete_element_b.__class__.__name__))
print(
f"{self.__class__.__name__} visit {concrete_element_b.__class__.__name__}"
)
Comment on lines -44 to +47
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteVisitor1.visitor_concrete_element_b refactored with the following changes:



class ConcreteVisitor2(Visitor):
Expand All @@ -53,12 +55,14 @@ class ConcreteVisitor2(Visitor):
"""

def visitor_concrete_element_a(self, concrete_element_a):
print("%s visit %s" % (self.__class__.__name__,
concrete_element_a.__class__.__name__))
print(
f"{self.__class__.__name__} visit {concrete_element_a.__class__.__name__}"
)
Comment on lines -56 to +60
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteVisitor2.visitor_concrete_element_a refactored with the following changes:


def visitor_concrete_element_b(self, concrete_element_b):
print("%s visit %s" % (self.__class__.__name__,
concrete_element_b.__class__.__name__))
print(
f"{self.__class__.__name__} visit {concrete_element_b.__class__.__name__}"
)
Comment on lines -60 to +65
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConcreteVisitor2.visitor_concrete_element_b refactored with the following changes:



class Element(metaclass=ABCMeta):
Expand Down
4 changes: 2 additions & 2 deletions Creational/abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, name):
self.name = name

def __str__(self):
return "ProductA: %s" % self.name
return f"ProductA: {self.name}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AbstractProductA.__str__ refactored with the following changes:



class ConcreteProductA1(AbstractProductA):
Expand All @@ -39,7 +39,7 @@ def __init__(self, name):
self.name = name

def __str__(self):
return "ProductB: %s" % self.name
return f"ProductB: {self.name}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AbstractProductB.__str__ refactored with the following changes:



class ConcreteProductB1(AbstractProductB):
Expand Down
2 changes: 1 addition & 1 deletion Creational/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add(self, part):
self.__parts.append(part)

def show(self):
print('-'.join(item for item in self.__parts))
print('-'.join(self.__parts))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Product.show refactored with the following changes:



class Builder(metaclass=ABCMeta):
Expand Down
4 changes: 1 addition & 3 deletions Creational/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def __init__(self, *args, **kwargs):
def __call__(self, *args, **kwargs):
if self.__instance is None:
self.__instance=super().__call__(*args,**kwargs)
return self.__instance
else:
return self.__instance
return self.__instance
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Singleton.__call__ refactored with the following changes:



# Python3
Expand Down
2 changes: 1 addition & 1 deletion Structural/flyweight.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FlyweightFactory(object):
"""

def __init__(self):
self.__flyweights = dict()
self.__flyweights = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FlyweightFactory.__init__ refactored with the following changes:


fx = ConcreteFlyweight()
self.__flyweights["X"] = fx
Expand Down