Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

refactor: simplify OrderedDict arguments in lexer - #598

Merged
plamut merged 1 commit into
googleapis:masterfrom
plamut:simple-ordereddict-args
Apr 13, 2021
Merged

refactor: simplify OrderedDict arguments in lexer#598
plamut merged 1 commit into
googleapis:masterfrom
plamut:simple-ordereddict-args

Conversation

@plamut

@plamutplamut commented Apr 8, 2021

Copy link
Copy Markdown
Contributor

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 teamApril 8, 2021 13:48
@product-auto-labelproduct-auto-labelBot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Apr 8, 2021
@google-clagoogle-claBot 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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 steffnayApril 9, 2021 08:24
@plamut

Copy link
Copy Markdown
ContributorAuthor

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

@tswast

Copy link
Copy Markdown
Contributor

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.

@tswasttswast left a comment

Copy link
Copy Markdown
Contributor

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:masterApr 13, 2021
@plamut
plamut deleted the simple-ordereddict-args branch April 13, 2021 16:50
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis 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

@plamut@tswast@jimfulton