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

refactor: simplify OrderedDict arguments in lexer #598

Merged
merged 1 commit into from
Apr 13, 2021

Conversation

plamut
Copy link
Contributor

@plamut plamut commented Apr 8, 2021

Closes #599. 🦕

Python 3.6+ guarantees that kwargs order is preserved, thus we don't need to assure the order by passing the arguments as a list of tuples (we don't support Python 3.5 anymore). Results in a more compact and cleaner source (IMO).

There are still some OrderedDict instances in tests that could benefit from the same, but I'm not touching that to not cause merge conflicts with the tests refactoring changes @jimfulton is making right now.

PR checklist

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Python 3.6+ guarantees that kwargs order is preserved, thus we
don't need to assure the order by passing them as a list of tuples.
@plamut plamut requested review from a team and steffnay and removed request for a team April 8, 2021 13:48
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Apr 8, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 8, 2021
Comment on lines +52 to +53
# Token definition order is important, thus an OrderedDict is used. In addition, PEP 468
# guarantees us that the order of kwargs is preserved in Python 3.6+.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note - we still need to use OrderedDict instad of a regular dict, because the regular dict's key insertion order should be considered an implementation detail of CPython 3.6 (that behavior has only been promoted to a language spec in Python 3.7).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! I didn't realize kwargs became ordered a version earlier :-)

@plamut plamut requested review from jimfulton and removed request for steffnay April 9, 2021 08:24
@plamut
Copy link
Contributor Author

plamut commented Apr 9, 2021

@jimfulton Assigned to you if you have free cycles and want to get more familiar with the BigQuery code.

@tswast
Copy link
Contributor

tswast commented Apr 13, 2021

Python 3.6+ guarantees that kwargs order is preserved

This is true for CPython, but I recall that the language standard only makes this the case for Python 3.7+. Not that we support/test with alternative runtimes... Maybe worth bringing up in the Python meeting today.

Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

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

Much cleaner!

@plamut plamut merged commit c741c38 into googleapis:master Apr 13, 2021
@plamut plamut deleted the simple-ordereddict-args branch April 13, 2021 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify passing the arguments to OrderedDict in lexer
3 participants