Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog committed Oct 25, 2023
1 parent 9a7cb60 commit 313779b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions brewtils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from funcsigs import signature, Parameter as InspectParameter # noqa
else:
from inspect import signature, Parameter as InspectParameter # noqa
if (sys.version_info.major == 3 and sys.version_info.minor >= 8):

if sys.version_info.major == 3 and sys.version_info.minor >= 8:
from typing import get_args

__all__ = [
Expand Down Expand Up @@ -564,8 +565,9 @@ def _parameter_docstring(method, parameter):

return None


def _choices_type_hint(method, cmd_parameter):
if (sys.version_info.major == 3 and sys.version_info.minor >= 8):
if sys.version_info.major == 3 and sys.version_info.minor >= 8:
for _, arg in enumerate(signature(method).parameters.values()):
if arg.name == cmd_parameter:
if str(arg.annotation).startswith("typing.Literal"):
Expand All @@ -576,6 +578,7 @@ def _choices_type_hint(method, cmd_parameter):

return None


def _parameter_type_hint(method, cmd_parameter):
for _, arg in enumerate(signature(method).parameters.values()):
if arg.name == cmd_parameter:
Expand Down
11 changes: 6 additions & 5 deletions test/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from mock import Mock

if (sys.version_info.major == 3 and sys.version_info.minor >= 8):
if sys.version_info.major == 3 and sys.version_info.minor >= 8:
from typing import Literal

import brewtils.decorators
Expand Down Expand Up @@ -212,18 +212,19 @@ def cmd(foo: int) -> dict:
assert bg_cmd.output_type == "JSON"

def test_type_hints_choices(self):
if (sys.version_info.major == 3 and sys.version_info.minor >= 8):
if sys.version_info.major == 3 and sys.version_info.minor >= 8:

@command
def cmd(foo: Literal["a","b"] = "a") -> dict:
def cmd(foo: Literal["a", "b"] = "a") -> dict:
return foo

bg_cmd = _parse_method(cmd)

assert len(bg_cmd.parameters) == 1
assert bg_cmd.parameters[0].key == "foo"
assert bg_cmd.parameters[0].type == "Any"
assert bg_cmd.parameters[0].choices.value == ["a","b"]
assert bg_cmd.parameters[0].default == "a"
assert bg_cmd.parameters[0].choices.value == ["a", "b"]
assert bg_cmd.parameters[0].default == "a"
assert bg_cmd.parameters[0].optional is True

class TestDocString(object):
Expand Down

0 comments on commit 313779b

Please sign in to comment.