Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_of function refactoring #271

Open
alanking opened this issue Sep 13, 2024 · 0 comments
Open

child_of function refactoring #271

alanking opened this issue Sep 13, 2024 · 0 comments
Labels

Comments

@alanking
Copy link
Collaborator

This function could use some work...

def child_of(session, child_resc_name, resc_name):
if child_resc_name == resc_name:
return True
else:
while True:
child_resc = session.resources.get(child_resc_name)
parent_resc_id = child_resc.parent
if parent_resc_id is None:
break
parent_resc_name = None
for row in session.query(Resource.name).filter(
Resource.id == parent_resc_id
):
parent_resc_name = row[Resource.name]
if parent_resc_name == resc_name:
return True
child_resc_name = parent_resc_name
return False

  • else can be removed and reduce indentation by one for most of the function
  • The name could be better
  • The embedded for loop over the parent_id query is confusing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant