Skip to content

Commit

Permalink
Allow parameter decorator to passthrough None for type
Browse files Browse the repository at this point in the history
  • Loading branch information
1maple1 committed Jul 11, 2024
1 parent 23635c1 commit c2f91a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions brewtils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,20 @@ def echo(self, message):
"""

# Validate type against permitted string literals
if not isinstance(type, str):
# Try to map literal to string equivalent
temp_type = _format_type(type)
if temp_type in Parameter.TYPES:
type = temp_type
elif type not in Parameter.TYPES:
# Allowing type matching: string == String == STRING
for parameter_type in Parameter.TYPES:
if type.upper() == parameter_type.upper():
type = parameter_type
break
if type not in Parameter.TYPES:
raise ValueError(f"Unable to map type {type} to string literal")
if type:
if not isinstance(type, str):
# Try to map literal to string equivalent
temp_type = _format_type(type)
if temp_type in Parameter.TYPES:
type = temp_type
elif type not in Parameter.TYPES:
# Allowing type matching: string == String == STRING
for parameter_type in Parameter.TYPES:
if type.upper() == parameter_type.upper():
type = parameter_type
break
if type not in Parameter.TYPES:
raise ValueError(f"Unable to map type {type} to string literal")

if _wrapped is None:
return functools.partial(
Expand Down
2 changes: 1 addition & 1 deletion test/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def cmd6(foo):
assert cmd3.parameters[0].type == "Float"
assert cmd4.parameters[0].type == "Boolean"
assert cmd5.parameters[0].type == "Dictionary"
assert cmd6.parameters[0].type == "Any"
assert cmd6.parameters[0].type == None

with pytest.raises(ValueError):

Expand Down

0 comments on commit c2f91a2

Please sign in to comment.