Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 5 commits into from
Jan 9, 2020
Merged

simplify code and pep8 and apply black formatter #80

merged 5 commits into from
Jan 9, 2020

Conversation

jnozsc
Copy link
Contributor

@jnozsc jnozsc commented Jan 9, 2020

No description provided.

@mattrobenolt
Copy link
Member

Hi there. I’d argue that if we want to address formatting, we should just adopt black. https://github.com/psf/black

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')
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

@jnozsc
Copy link
Contributor Author

jnozsc commented Jan 9, 2020

I apply black formatter in f8db6cc

@jnozsc jnozsc changed the title simplify code and pep8 simplify code and pep8 and apply black formatter Jan 9, 2020
@mattrobenolt
Copy link
Member

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!

@mattrobenolt
Copy link
Member

btw did you run black with any arguments?

@jnozsc
Copy link
Contributor Author

jnozsc commented Jan 9, 2020

just

cd  ua_parser
black user_agent_parser.py

@mattrobenolt
Copy link
Member

Perfect, thanks. :)

@mattrobenolt mattrobenolt merged commit 3aff3c4 into ua-parser:master Jan 9, 2020
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.

2 participants