worker
has same name as its encolising class Worker
63
64 self.context = Context(parent=aj.context)
65 self.context.session = self.gate.session
66 self.context.worker = self 67 self.handler = HttpMiddlewareAggregator([
68 AuthenticationMiddleware.get(self.context),
69 CentralDispatcher.get(self.context),
worker
has same name as its encolising class Worker
47
48class Worker():
49 def __init__(self, stream, gate):
50 aj.worker = self 51 self.stream = stream
52 self.gate = gate
53 aj.master = False
pidfile
has same name as its encolising class PidFile
11
12 def __init__(self, path):
13 self.path = path
14 self.pidfile = None15
16 def __enter__(self):
17 self.pidfile = open(self.path, "a+")
totp
has same name as its encolising class TOTP
6class TOTP:
7 def __init__(self, user, secret):
8 self.user = user
9 self.totp = pyotp.TOTP(secret)10
11 def make_b64qrcode(self):
12 url = f'otpauth://totp/{self.user}?secret={self.totp.secret}'
There is a class member with the same name (not considering the case difference) as its enclosing class.
This can cause confusion while reading the code later on keeping a track of what the field represents. It is strongly recommended to provide self-explanatory names so that someone who's reading the code doesn't have to spend time keeping a track of the variable/method names.
class Orange:
'''We mean, the fruit.'''
orange = "#FFA500"
# Other class implementations
def get_orange(self):
return abc
fruit = Orange()
render_to_frontend(fruit.orange) # Rendering a color, but one can get confused with the fruit
render_bg(fruit.get_orange) # Not clear that `get_orange` is returning a color
class Orange:
'''We mean, the fruit.'''
color = "#FFA500"
# Other class implementations
def get_color(self):
return abc
fruit = Orange()
render_to_frontend(fruit.color) # Evident that we are working with color
render_bg(fruit.get_color) # Evident that we are fetching the fruit's color