-
Notifications
You must be signed in to change notification settings - Fork 158
simplify code and pep8 and apply black formatter #80
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
Conversation
Hi there. I’d argue that if we want to address formatting, we should just adopt black. https://github.com/psf/black |
ua_parser/user_agent_parser.py
Outdated
v2 = jsParseBits['js_user_agent_v2'] or None | ||
if 'js_user_agent_v3' in jsParseBits: | ||
v3 = jsParseBits['js_user_agent_v3'] or None | ||
v1 = jsParseBits.get('js_user_agent_v1') |
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.
These also aren’t equivalent code. So I’m not sure what the goal here is or if the change in behavior is fine.
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.
aren't they? may i know in which case? I think they are same
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.
>>> jsParseBits = {'js_user_agent_v1': False, 'js_user_agent_v2': ''}
>>> jsParseBits.get('js_user_agent_v1')
False
>>> jsParseBits['js_user_agent_v1'] or None
>>>
If the key exists, but it's any falsey value. The falsey value will be returned instead of None.
In theory, v1 = jsParseBits.get('js_user_agent_v1') or None
would be almost equivalent and shortened.
The only difference here now is that v1
is being defined guaranteed, whereas before it wasn't. Though I'd agree having it guaranteed defined would be a bit better to avoid any potential NameError.
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.
oh, thanks. fix in 9da6ff6
I apply |
Cool, I think this is better. I'll likely follow up then on actually integrating black into CI rather than this just one-off attempt and let formatting slip. Thanks! |
btw did you run |
just cd ua_parser
black user_agent_parser.py |
Perfect, thanks. :) |
No description provided.