Create action object given head token of action phrase in docstring.
Condition token used to avoid traversing into the condition phrase dependency subtree of the docstring.
Source code in library_analyzer/processing/dependencies/_get_dependency.py
| def extract_action(action_token: Token, condition_token: Token) -> Action:
"""
Create action object given head token of action phrase in docstring.
Condition token used to avoid traversing into the condition phrase dependency subtree of the docstring.
"""
action_tokens = []
action_lefts = list(action_token.lefts)
action_rights = list(action_token.rights)
for token in action_lefts:
if token != condition_token:
action_tokens.extend(extract_lefts_and_rights(token))
action_tokens.append(action_token.text)
for token in action_rights:
if token != condition_token:
action_tokens.extend(extract_lefts_and_rights(token))
# Remove trailing punctuation
if any(p == action_tokens[-1] for p in [",", "."]):
del action_tokens[-1]
action_text = " ".join(action_tokens)
ignored_phrases = [
"ignored",
"not used",
"no impact",
"only supported",
"only applies",
]
illegal_phrases = ["raise", "exception", "must be", "must not be"]
if any(phrase in action_text.lower() for phrase in ignored_phrases):
return ParameterIsIgnored(action=action_text)
elif any(phrase in action_text.lower() for phrase in illegal_phrases):
return ParameterIsIllegal(action=action_text)
else:
return Action(action=action_text)
|