jendrikseipp / vulture

Find dead Python code
MIT License
3.41k stars 150 forks source link

Treat non-python files as a string constant #217

Closed colinc719 closed 4 years ago

colinc719 commented 4 years ago

Would it make sense to have the text of non-python files still go through Vulture._handle_string? For instance,

class Temp:
    def __init__(self):
        self.arg = None

pattern = '{self.arg!s}'
assert pattern.format(self=Temp())

correctly produces no problems, but if you move the pattern to a separate txt file

temp.txt:

{self.arg!s}

temp.py

class Temp:
    def __init__(self):
        self.arg = None

pattern = open('temp.txt').read()
assert pattern.format(self=Temp())

It will produce "unused attribute 'arg'".

jendrikseipp commented 4 years ago

Vulture will parse a file not ending with .py if it's passed on the command line and if it contains correct Python syntax. I don't think it makes sense to consider files that don't contain valid Python.