-
Notifications
You must be signed in to change notification settings - Fork 143
Sourcery Starbot ⭐ refactored wklken/py-patterns #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
else: | ||
self.successor.handle_request(request) | ||
|
||
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
else: | ||
self.successor.handle_request(request) | ||
|
||
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
else: | ||
self.successor.handle_request(request) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,8 +79,7 @@ def output(self, value): | |
if __name__ == '__main__': | ||
context = Context("in", "out") | ||
|
||
l = [] | ||
l.append(TerminalExpression()) | ||
l = [TerminalExpression()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
l.append(TerminalExpression()) | ||
l.append(NoterminalExpression()) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == '__main__': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
if __name__ == '__main__': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class ConcreteVisitor2(Visitor): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class Element(metaclass=ABCMeta): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ def __init__(self, name): | |
self.name = name | ||
|
||
def __str__(self): | ||
return "ProductA: %s" % self.name | ||
return f"ProductA: {self.name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class ConcreteProductA1(AbstractProductA): | ||
|
@@ -39,7 +39,7 @@ def __init__(self, name): | |
self.name = name | ||
|
||
def __str__(self): | ||
return "ProductB: %s" % self.name | ||
return f"ProductB: {self.name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class ConcreteProductB1(AbstractProductB): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class Builder(metaclass=ABCMeta): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
# Python3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ class FlyweightFactory(object): | |
""" | ||
|
||
def __init__(self): | ||
self.__flyweights = dict() | ||
self.__flyweights = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
fx = ConcreteFlyweight() | ||
self.__flyweights["X"] = fx | ||
|
There was a problem hiding this comment.
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:replace-interpolation-with-fstring
)