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

vdk-jupyter: fix bug in detecting run functions #2721

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

antoniivanov
Copy link
Collaborator

We are using re.search(r"def run\(job_input", content) which is very bad practice. Never use regex unless you have a official contract or specification that promises the regex will work.

The regex breaks in so many cases :

  • put some space anywhere def run<space>(job_input) ,
  • def run is defined on multiple lines
  • coments .
  • def run ins in string literal and not really a method
  • and probably much more I cannot think of.

In general rule, I really think it's bad idea to do parsing (regex is type of parsing) without implement strict contract and specification.

The solution to the problem here simple fortunately. It is to use Python's ast (Abstract Syntax Tree) module to parse Python code.

We are using `re.search(r"def run\(job_input", content)` which is very
bad practice. Never use regex unless you have a official contract or
specification that promises the regex will work.

The regex breaks in so many cases :
- put some space anywhere `def run<space>(job_input)` ,
- def run is defined on multiple lines
- coments .
- def run ins in string literal and not really a method
- and probably much more I cannot think of.

In general rule, I really think it's bad idea to do parsing (regex is
type of parsing) without implement strict contract and specification.

The solution to the problem here  simple fortunately. It is to use
Python's ast (Abstract Syntax Tree) module to parse Python code.
@antoniivanov antoniivanov merged commit 90c6518 into main Sep 29, 2023
8 checks passed
@antoniivanov antoniivanov deleted the person/aivanov/jupyter-summary branch September 29, 2023 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants