python-minifier
python-minifier copied to clipboard
better detection for whether or not it is safe to minify variable names
python-minifier does a few checks to ensure that it's safe to minify variables. I've gathered a short list of things which should probably be checked for, along with the checks that already exist. This won't entirely prevent problems with identifier minifying, but it will prevent many of the more-common gotcha's.
builtins:
These can be checked for in the same way that locals(), globals(), and the rest are checked for.
-
locals(already checked for) -
globals(already checked for) -
getattr -
setattr -
dir -
vars(already checked for) -
compile -
eval(already checked for) -
exec(already checked for)
imported modules:
These can be checked for by checking which modules are listed in import statements.
-
__main__ -
traceback -
inspect -
symtable -
dis -
bdb -
pdb -
trace
global (module-level) dunders:
-
__getattr__ -
__dir__ -
__all__
dunder attributes:
-
.__getattribute__ -
.__getattr__ -
.__setattr__ -
.__dict__ -
.__dir__ -
.__code__(on function objects)
frame-object attributes:
-
.f_locals -
.f_globals -
.f_builtins -
.f_code
specific things from modules:
-
sys.settrace -
sys._getframe -
operator.attrgetter -
operator.methodcaller