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

👌 IMPROVE: Add typing to QueryBuilder #5063

Merged
merged 8 commits into from
Aug 12, 2021

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Aug 11, 2021

This PR principally adds typing to aiida/orm/querybuilder.py, and does a small bit of refactoring:

  1. Make the __init__ and append constructor variables more explicit, as opposed to relying on kwargs which obfuscates the allowed inputs for the user
  2. Removes legacy self._aliased_path variable, whose use in relation to the direction joining keyword was actually removed in v0.8 (now direction is converted to with_outgoing or with_incoming before storage, and similarly its value is converted from an int to a tag string)
  3. Removal of autotag=True from .append calls; another legacy bit of code

The PR is intended as preparation for migration to sqlalchemy 1.4 (and dropping sqlalchemy-utils)

@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #5063 (1f123b5) into develop (79d2d27) will increase coverage by 0.05%.
The diff coverage is 80.28%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5063      +/-   ##
===========================================
+ Coverage    80.43%   80.47%   +0.05%     
===========================================
  Files          530      530              
  Lines        36946    36944       -2     
===========================================
+ Hits         29712    29727      +15     
+ Misses        7234     7217      -17     
Flag Coverage Δ
django 74.99% <80.28%> (+0.05%) ⬆️
sqlalchemy 73.87% <80.28%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/orm/implementation/querybuilder.py 77.98% <75.00%> (-0.20%) ⬇️
aiida/orm/implementation/backends.py 90.33% <80.00%> (-9.67%) ⬇️
aiida/orm/querybuilder.py 82.22% <80.47%> (+2.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79d2d27...1f123b5. Read the comment docs.

In preparation for migration to sqlalchemy 1.4
@ltalirz ltalirz removed their request for review August 12, 2021 15:13
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Looks good, just have a question about the type styling

Comment on lines 64 to 67
NODE_CLS_TYPE = Type[Any] # pylint: disable=invalid-name
PROJECT_TYPE = Union[str, dict, Sequence[Union[str, dict]]] # pylint: disable=invalid-name
FILTER_TYPE = Dict[str, Any] # pylint: disable=invalid-name
ROW_TYPE = Any # pylint: disable=invalid-name
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use here all-caps, but the CamelCase for PathItemType further down? I see most built in types having CamelCase, so is that the standard? Should we change these to have the same style, even though they are "constants" and normally would be all-caps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't know really lol, I think I say it somewhere else and kind of liked it, to distinguish these type annotation variables from regular one. But its not a big deal, so fine to change

Copy link
Contributor

Choose a reason for hiding this comment

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

I just find it confusing when reading the type annotations seeing PathItemType and then ROW_TYPE. Think if that is also RowType it would be clearer and finding where the definition comes from is easy

Copy link
Member Author

Choose a reason for hiding this comment

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

no worries, changed it 👍

@sphuber sphuber self-requested a review August 12, 2021 20:19
@chrisjsewell chrisjsewell merged commit b826ae2 into aiidateam:develop Aug 12, 2021
@chrisjsewell chrisjsewell deleted the type-querybuilder branch August 12, 2021 20:43
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