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

better detection for whether or not it is safe to minify variable names #92

Open
kotnen opened this issue Aug 5, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@kotnen
Copy link

kotnen commented Aug 5, 2023

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
@dflook dflook added the enhancement New feature or request label Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants