amazon-braket / amazon-braket-build-tools

Apache License 2.0
5 stars 3 forks source link

fix: avoid plugin failure in case with parameters after *args #14

Closed rmshaffer closed 1 year ago

rmshaffer commented 1 year ago

Issue #, if available:

Description of changes: In a case where a function has parameters listed after *args (and no parameters before), the plugin hits an unhandled IndexError exception and fails to complete.

Here is the exception that is hit (and is avoided with these changes):

    def _check_argument_order(
        self,
        arg_name: str,
        arg_index: int,
        arg_type: ArgType,
        context: DocContext,
        node: ast.FunctionDef,
    ) -> None:
        expected_index = 0
        if context.previous_arg is None:
>           if node.args.args[0].arg in self.RESERVED_ARGS:
E           IndexError: list index out of range

src\braket\flake8_plugins\braket_checkstyle_plugin.py:262: IndexError

Testing done: Added a unit test to verify that the problem is fixed.

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

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

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (53b3954) 97.81% compared to head (09e6b4f) 97.81%. Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #14 +/- ## ======================================= Coverage 97.81% 97.81% ======================================= Files 2 2 Lines 320 320 Branches 95 95 ======================================= Hits 313 313 Misses 2 2 Partials 5 5 ``` | [Files Changed](https://app.codecov.io/gh/amazon-braket/amazon-braket-build-tools/pull/14?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amazon-braket) | Coverage Δ | | |---|---|---| | [src/braket/\_build\_tools/\_version.py](https://app.codecov.io/gh/amazon-braket/amazon-braket-build-tools/pull/14?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amazon-braket#diff-c3JjL2JyYWtldC9fYnVpbGRfdG9vbHMvX3ZlcnNpb24ucHk=) | `100.00% <100.00%> (ø)` | | | [.../braket/flake8\_plugins/braket\_checkstyle\_plugin.py](https://app.codecov.io/gh/amazon-braket/amazon-braket-build-tools/pull/14?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=amazon-braket#diff-c3JjL2JyYWtldC9mbGFrZThfcGx1Z2lucy9icmFrZXRfY2hlY2tzdHlsZV9wbHVnaW4ucHk=) | `97.79% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.