-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
refactot Route.all_plugins() #1306
base: master
Are you sure you want to change the base?
Conversation
My code accurately reproduces original functional, but is it correct? In original code `unique` collects plugin names to avoid repeats. If plugin has no name, this check not. So, noname plugin can repeats. Is it right logic?
bottle.py
Outdated
for plugins in self.plugins, self.app.plugins: | ||
for p in reversed(plugins): | ||
if p not in skips and type(p) not in skips: | ||
name = getattr(p, 'name', False) |
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.
Do you really need False
here ? getattr
will return None
by default.
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.
@oz123 getattr()
raises AttibuteError
by default! So there needs to be a third argument, but IMHO it should be None
and not False
.
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.
@oz123, you wrong, if len(args) == 2 and obj has no attr, error rises:
getattr(None, 'name')
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-41470b2f07a7>", line 1, in <module>
getattr(None, 'name')
AttributeError: 'NoneType' object has no attribute 'name'
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.
Yeah, my bad one. Mixed it with dict.get
!
bottle.py
Outdated
if True in self.skiplist: return | ||
skips = set(self.skiplist) | ||
for plugins in self.plugins, self.app.plugins: | ||
for p in reversed(plugins): |
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.
Compared to the original code I find this much harder to understand.
normally a for
loop in python is in the form:
for single in plural
do something ...
You wrote for plugins
in <other list of plugins>
. I didn't dive into analyzing in depth to see what is the other set of plugins. But this form of for
will immediately cause a headache for a lot of people.
Further, an embedded for loop is harder to understand compared to a simple for loop.
@SergBobrovsky you do a really cool job on those PRs. Keep up and take the critics as constructive criticism. |
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.
My code accurately reproduces original functional, but is it correct?
In original code
unique
collects plugin names to avoid repeats. If plugin has no name, this check not. So, noname plugin can repeats. Is it right logic?