Skip to content

Commit

Permalink
Update ct-app/core/components/utils.py
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
jeandemeusy and coderabbitai[bot] authored Jan 22, 2025
1 parent 4ad64e0 commit 8fad349
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions ct-app/core/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,17 @@ async def balanceInChannels(cls, channels: list) -> dict[str, dict]:

@classmethod
def decorated_methods(cls, file: str, target: str):
with open(file, "r") as f:
source_code = f.read()

tree = ast.parse(source_code)
try:
with open(file, "r") as f:
source_code = f.read()

tree = ast.parse(source_code)
except FileNotFoundError as e:
cls().error(f"Could not find file {file}: {e}")
return []
except SyntaxError as e:
cls().error(f"Could not parse {file}: {e}")
return []

keepalive_methods = []

Expand All @@ -165,15 +172,20 @@ def decorated_methods(cls, file: str, target: str):
continue

for decorator in node.decorator_list:
if isinstance(decorator, ast.Call):
args_name = [arg.id for arg in decorator.args]
try:
if isinstance(decorator, ast.Call):
args_name = [arg.id for arg in decorator.args if isinstance(arg, ast.Name)]

if decorator.func.id != target and target not in args_name:
continue
if not hasattr(decorator.func, 'id') or (decorator.func.id != target and target not in args_name):
continue

elif isinstance(decorator, ast.Name):
if decorator.id != target:
elif isinstance(decorator, ast.Name):
if not hasattr(decorator, 'id') or decorator.id != target:
continue
else:
continue
except AttributeError:
continue

keepalive_methods.append(node.name)
break
Expand Down

0 comments on commit 8fad349

Please sign in to comment.