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

update: forcing explicit optional types #17

Merged
merged 3 commits into from
Nov 3, 2023
Merged

update: forcing explicit optional types #17

merged 3 commits into from
Nov 3, 2023

Conversation

krneta
Copy link
Contributor

@krneta krneta commented Nov 2, 2023

Issue #, if available:

Description of changes:

Testing done:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@krneta krneta requested a review from ajberdy November 2, 2023 20:37
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bcf94b3) 100.00% compared to head (6b40b57) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #17   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          326       339   +13     
  Branches        97       103    +6     
=========================================
+ Hits           326       339   +13     
Files Coverage Δ
.../braket/flake8_plugins/braket_checkstyle_plugin.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -87,6 +87,7 @@ class _Visitor(ast.NodeVisitor):
"BCS020": "Function '%s' has return documentation but no return type.",
"BCS021": "Function '%s' is missing return documentation.",
"BCS022": "Found '%d' invalid indents starting with line ('%s').",
"BCS023": "Argument '%s' is optional but type hint doesn't end with '| None'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer we avoid "optional" here as it is ambiguous and doesn't exactly align with the requirements. bool = False or str = '' are both optional args that don't include None in their type. It's an existing pain point that Optional[...] doesn't align with whether an arg is "optional", so might as well use clearer terms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Will change.

and isinstance(default_value, ast.Constant)
and default_value.value is None
):
if not documented_type.endswith("|None") and not documented_type.startswith("Optional"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to do this through attributes without string processing? Seems this allows str | None and Optional[str], but what about Union[str, None] or None | str?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to standardize on putting | None last, and we'll see if we need to deal with edge cases for Union.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually checking through the types would be better, but it would mean processing them twice or refactoring around how we deal with types. I'm not sure that it's worth it at this point.

Returns:
int: value of the function
"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: newline at eof

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, thanks!

@krneta krneta merged commit 11dbf4d into main Nov 3, 2023
11 checks passed
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