Skip to content

Commit 485f0b9

Browse files
committed
Add utility to check if an argument is positional
Add an analogous but opposite function to "is_option_arg" to improve readability.
1 parent a375aa5 commit 485f0b9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tap/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ def is_option_arg(*name_or_flags) -> bool:
171171
return any(name_or_flag.startswith('-') for name_or_flag in name_or_flags)
172172

173173

174+
def is_positional_arg(*name_or_flags) -> bool:
175+
"""Returns whether the argument is a positional arg (as opposed to an optional arg).
176+
177+
:param name_or_flags: Either a name or a list of option strings, e.g. foo or -f, --foo.
178+
:return: True if the argument is a positional arg, False otherwise.
179+
"""
180+
return not is_option_arg(*name_or_flags)
181+
182+
174183
def tokenize_source(obj: object) -> Generator:
175184
"""Returns a generator for the tokens of the object's source code."""
176185
source = inspect.getsource(obj)

0 commit comments

Comments
 (0)