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

DM-35312 Add support for python typing of Fields #79

Merged
merged 1 commit into from Jun 28, 2022
Merged

Conversation

natelust
Copy link
Contributor

Add support for specifying the type of Fields with python class
typing syntax. This will ensure the appropriate type is inferred
from a Fields get method, type checking when setting with
set, as well as setting appropriate dtypes where applicable at
runtime.

@natelust natelust force-pushed the tickets/DM-35312 branch 2 times, most recently from f3c582d to cb8a4f6 Compare June 23, 2022 20:29
@codecov
Copy link

codecov bot commented Jun 23, 2022

Codecov Report

Merging #79 (f57788a) into main (0bb880f) will increase coverage by 0.22%.
The diff coverage is 89.70%.

❗ Current head f57788a differs from pull request most recent head d87ebfd. Consider uploading reports for the commit d87ebfd to get more accurate results

@@            Coverage Diff             @@
##             main      #79      +/-   ##
==========================================
+ Coverage   84.07%   84.30%   +0.22%     
==========================================
  Files          40       40              
  Lines        3008     3172     +164     
==========================================
+ Hits         2529     2674     +145     
- Misses        479      498      +19     
Impacted Files Coverage Δ
python/lsst/pex/config/configurableField.py 78.97% <78.57%> (-0.42%) ⬇️
python/lsst/pex/config/listField.py 81.21% <80.00%> (-0.71%) ⬇️
python/lsst/pex/config/configChoiceField.py 84.82% <83.33%> (-0.32%) ⬇️
python/lsst/pex/config/configField.py 79.72% <84.61%> (-0.87%) ⬇️
python/lsst/pex/config/config.py 91.48% <89.65%> (+0.04%) ⬆️
python/lsst/pex/config/dictField.py 84.88% <95.83%> (+2.53%) ⬆️
python/lsst/pex/config/configDictField.py 87.17% <100.00%> (ø)
tests/test_Config.py 95.63% <100.00%> (+0.14%) ⬆️
tests/test_dictField.py 95.19% <100.00%> (+0.87%) ⬆️

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 0bb880f...d87ebfd. Read the comment docs.

@@ -60,6 +67,18 @@
YamlLoaders += (CLoader,)
except ImportError:
pass
else:
YamlLoaders = ()
doImport = None
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already set from the try/except earlier? I'm also a bit surprised it's not assigned to something else when yaml is available, but maybe that will be explained by code below.

Copy link
Member

Choose a reason for hiding this comment

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

I feel that this change should be a separate commit. It's probably better to move the setting down from the import check above but it doesn't seem directly related to the other changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can move it or drop it. This just fell under "a few other changes to make type checking happy". My checker was unable to tell that YamlLoaders would be bound, and was complaining about a possibly unbound variable, which is understandable as it would need to know about the logic in the exception handler triggering setting variables that will later be used in an if statement check.

python/lsst/pex/config/config.py Outdated Show resolved Hide resolved
python/lsst/pex/config/config.py Outdated Show resolved Hide resolved
Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

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

Accidentally put my overview comments on the pipe_tasks PR (lsst/pipe_tasks#692). I blame VSCode's GitHub plugin, which I tried to use to do this review with mixed results.

python/lsst/pex/config/config.py Outdated Show resolved Hide resolved
python/lsst/pex/config/config.py Show resolved Hide resolved
python/lsst/pex/config/config.py Outdated Show resolved Hide resolved
python/lsst/pex/config/config.py Outdated Show resolved Hide resolved
python/lsst/pex/config/configField.py Outdated Show resolved Hide resolved
python/lsst/pex/config/listField.py Outdated Show resolved Hide resolved
python/lsst/pex/config/listField.py Outdated Show resolved Hide resolved
tests/test_Config.py Show resolved Hide resolved
tests/test_dictField.py Show resolved Hide resolved
tests/test_Config.py Show resolved Hide resolved
@timj
Copy link
Member

timj commented Jun 24, 2022

@TallJimbo (1) we do use black in pex_config (2) there is a test matrix and you can see that only 3.10 is passing at the moment.

@timj
Copy link
Member

timj commented Jun 24, 2022

And I don't think @natelust is running pre-commit because you can see that the formatting check is also failing (hence your comment about indenting above).

Add support for specifying the type of Fields with python class
typing syntax. This will ensure the appropriate type is inferred
from a Fields __get__ method, type checking when setting with
__set__, as well as setting appropriate dtypes where applicable at
runtime.
@natelust natelust merged commit 157d100 into main Jun 28, 2022
@natelust natelust deleted the tickets/DM-35312 branch June 28, 2022 16:19
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.

None yet

3 participants