Closed Wxl19980214 closed 2 years ago
working on it
Hi, I am currently stuck on how to distinguish actual code with string. For example:
f = open('something') # code f = "open('something)" # str f = 'Today the weather is good and I opened the door.' # str
Only the first one should we output the warning. But what I am doing now is to check whether the line contains key word 'open', which obviously not going to work. If someone wants to mess with the system, they can also do stuff like this:
f = "Path('fool.txt').write_text()"
Is there any good way to detect the difference?
@Wxl19980214 We can automatically ignore strings or comments, I think we can open an issue if we see it's too complex, I don't see a user writing an open command inside a str in purpose"Path('fool.txt').write_text()"
, unless it's commented out #Path('fool.txt').write_text()
.
Me2, I don't expect people doing weird stuff. I think parso automatically ignore comments so we got that off the table. One last thing is maybe people can give a variable named write_text? It looks legit. Do we just ignore this case as well, or are we somehow do stuff like string pattern?
Maybe some regex matching, it's write_text(
, I'm sure a bit more sophisticated regex will solve this + most of those problems are probably already solved.
TBH if we omit the situation where user mess up with our system. Simple contain would suffice? We could just check if statement like these .write_text( , open(, .to_csv( are included in our code
simple contains will suffice?
I think it does.
@Wxl19980214 is this ready for review?
@idomic Yes
Describe your changes
Parse notebook code, if it contains statement such as open, output warning.
Issue ticket number and link
Closes #16
Checklist before requesting a review