-
Notifications
You must be signed in to change notification settings - Fork 64
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
Changing function signature of parse
to accept the file content instead of a file
#1706
base: main
Are you sure you want to change the base?
Conversation
…tead of a file This PR changes the way `parse` works (in a backwards compatible way). Instead of parsing a `File`, we parse the file contents (and a path). The reasoning behind this is that almost all language frontends currently need to read the file contents and we can harmonize this. This will also allow us to provide more common statistics about the parsing context in the future.
Quality Gate passedIssues Measures |
...ge-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt
Show resolved
Hide resolved
if (path != null) { | ||
path.absolute().toString() | ||
} else { | ||
"<unknown>" |
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.
To we want this constant for cpg consistency? Python recommends <string>
see https://docs.python.org/3/library/functions.html#compile
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.
We are using ast.Parse and the default parameter here was <unknown>
. See https://docs.python.org/3/library/ast.html#ast.parse
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.
Funny, that the ast.parse doc says:
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
But I'm ok with the "unknown". This should probably a sane constant for all frontends if there is no file available?
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.
Funny, that the ast.parse doc says:
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
But I'm ok with the "unknown". This should probably a sane constant for all frontends if there is no file available?
I was intentionally using the python specific value here, but I am fine with either way. Not sure if the SARIF standard defines something in this case, since we are using the location information from SARIF.
This PR changes the way
parse
works (in a backwards compatible way). Instead of parsing aFile
, we parse the file contents (and a path). The reasoning behind this is that almost all language frontends currently need to read the file contents and we can harmonize this. This will also allow us to provide more common statistics about the parsing context in the future.Language frontends that can potentially leverage this: