Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SergBobrovsky
Copy link
Contributor

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?

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)
Copy link
Contributor

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.

Copy link

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.

Copy link
Contributor Author

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'

Copy link
Contributor

@oz123 oz123 Jan 5, 2021

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):
Copy link
Contributor

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.

@oz123
Copy link
Contributor

oz123 commented Jan 5, 2021

@SergBobrovsky you do a really cool job on those PRs. Keep up and take the critics as constructive criticism.

@SergBobrovsky SergBobrovsky reopened this Jan 5, 2021
Copy link
Contributor

@oz123 oz123 left a comment

Choose a reason for hiding this comment

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

Much better now.

Neat: Fix the typo in the PR's title:

refactot Route.all_plugins() #1306 -> refactor Route.all_plugins() #1306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants