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

since the ast AnnAssign class can be value-less, avoid resolution fai… #148

Merged
merged 3 commits into from Jul 18, 2022

Conversation

speediedan
Copy link
Contributor

@speediedan speediedan commented Jul 16, 2022

Thanks so much to everyone in the community (especially @mauvilsa !) for this immensely valuable package!

This PR fixes #147.

What does this PR do?

According to the current cpython abstract grammar definition, the value of an ast.AnnAssign class can be None (also discussed in PEP 526) whether within methods or in the class body. So though it's usually considered bad practice stylistically, since it's valid syntax, AST-based parameter resolution should handle this edge case I think.

I've written a tiny one-line fix for this issue and added an associated test in the parameter-resolver test module.

In case it's relevant, an alternate approach to testing that I validated was to simply add a value-less annotation within the __init__ method of ClassA but I ultimately decided that isolating the test the way I've done in this PR might make more sense.

  • Did you read the contributing guideline?
  • [n/a] Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

…lure in this stylistically questionable but syntactically valid edge case
@codecov-commenter
Copy link

Codecov Report

Merging #148 (f241f0e) into master (c989d91) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #148   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         4170      4171    +1     
=========================================
+ Hits          4170      4171    +1     
Flag Coverage Δ
py3.10_all 99.90% <100.00%> (+<0.01%) ⬆️
py3.6 91.02% <100.00%> (+<0.01%) ⬆️
py3.6_all 99.68% <100.00%> (+<0.01%) ⬆️
py3.7_all 99.80% <100.00%> (+<0.01%) ⬆️
py3.8 91.29% <100.00%> (+<0.01%) ⬆️
py3.8_all 99.88% <100.00%> (+<0.01%) ⬆️
py3.9_all 99.88% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
jsonargparse/parameter_resolvers.py 100.00% <100.00%> (ø)

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 c989d91...f241f0e. Read the comment docs.

@speediedan speediedan marked this pull request as ready for review July 16, 2022 03:43
@mauvilsa mauvilsa added the bug Something isn't working label Jul 18, 2022
@mauvilsa mauvilsa self-requested a review July 18, 2022 05:30
Copy link
Member

@mauvilsa mauvilsa left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! This fixes a bug, so please do add an entry in the Fixed section of the changelog.

@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@speediedan
Copy link
Contributor Author

Looks great, thank you! This fixes a bug, so please do add an entry in the Fixed section of the changelog.

Done! Thanks again for your invaluable contribution to the community with this package. I look forward to continuing using it in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle edge cases in AST-based parameter resolution where AnnAssign is value-less
3 participants