-
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add a helper to find if a function has a func/method call #302
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
base: main
Are you sure you want to change the base?
Conversation
python/py_helpers.test.py
Outdated
|
||
self.assertTrue(node.func_has_call("spam", "sort")) | ||
self.assertTrue(node.func_has_call("eggs", "get")) | ||
self.assertFalse(node.func_has_call("srt", "sorted")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be confused by the description. Shouldn't this be caught as using sorted
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because it can search only within a function but sorted(...)
is assigned to the variable srt
(not function) in the global scope. I forgot to mention that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. I'd add then another test for a case when sorted
is used inside of function, to better show the difference, and have one test checking for function call (instead of just methods).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would still be cheating with extra steps... would it be possible to prohibit that to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want that I can simply search the entire code instead of a function. What about something like this?
node.block_has_call('sorted', 'function') # finds sorted within function
node.block_has_call('sorted') # finds sorted in the entire code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would that find also reassignments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should find any occurrences of the method/function being called.
we should be able to test this with freeCodeCamp/freeCodeCamp#60285 |
I tried a few times but it doesn't work for me |
What's failing? I've tried
and that seems fine. Obviously it doesn't use the new helpers, but there weren't any issues building or testing. |
Even after |
Hey @Dario-DC these are the steps I took to get things working
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @ojeytonwilliams 🙏 |
Checklist:
Update index.md
)Closes #XXXXX
The main purpose of this helper would be to verify that specific built-in functions or methods (such as
.sort()
orsorted()
) are not used by campers to solve DSA labs.Not sure if we need it, but you can either choose to check that the method/function
spam
is called anywhere within a specific functionfoo
with:or verify that
spam
is called anywhere within the user's code: