pyminifier icon indicating copy to clipboard operation
pyminifier copied to clipboard

Obfuscation conflicts with submodules and function names

Open themiurgo opened this issue 9 years ago • 1 comments

Pyminifier seems to have problems with submodules that have the same name as modules, such as datetime.datetime:

# test.py
import datetime
print datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")

# test_obf.py
# Produced by `pyminifier -O test.py > test_obf.py`
import datetime
q=datetime.strptime
V=datetime.datetime
print V.strptime("21/11/06 16:30","%d/%m/%y %H:%M")
# Created by pyminifier (https://github.com/liftoff/pyminifier)

$ python test_obf.py
Traceback (most recent call last):
  File "test_min.py", line 2, in <module>
    q=datetime.strptime
AttributeError: 'module' object has no attribute 'strptime'

It also seems to have issues when there is a method (even a class method) that has the same name as a module.

# test2.py
import geojson
class ExampleClass(object):
    def geojson(self):
        return {'something': 'foo'}
p = geojson.Point((-115.81, 37.24))

#test2_obf.py
# Produced by `pyminifier -O test2.py > test2_obf.py`
import P
s=object
d=P.Point
class e(s):
 def P(self):
  return{'something':'foo'}
p=d((-115.81,37.24))
# Created by pyminifier (https://github.com/liftoff/pyminifier)

$ python test2_obf.py 
Traceback (most recent call last):
  File "test2_obf.py", line 1, in <module>
    import P
ImportError: No module named P

themiurgo avatar Mar 27 '15 15:03 themiurgo

any workaround?

diggerdu avatar Oct 11 '18 14:10 diggerdu