Issue about imp.get_magic()
laike9m opened this issue · 2 comments
Hi rocky, I noticed imp.get_magic()
is invokded in 4 places in the codebase, each given a different name. Since imp is deprecated, I would like to replace it with importlib.util.MAGIC_NUMBER
, meanwhile put them into one single place. Is there any file that you suggest me to put the magic number into, or you prefer to keep it in multiple places?
First and foremost, thanks for offering help to clean up this mess.
The file xdis.magic
is the most low-level of the 4 places and I think the right place to put an imp.get_magic()
replacement. In fact all of the files other than magic.py
itself import magic
.
But some caution needs to be done in using import.lib.util.MAGIC_NUMBER
: in the master branch, xdis
has to support Python 2.7 to 3.8. and according to the import importlib.util doc importlib.util.MAGIC_NUMBER
was added in Python 3.4.
One way to get around this is code like:
def get_magic():
If PYTHON_VERSION >= 3.4:
import import.util as import_util
return import_util.MAGIC_NUMBER
else:
import imp
return imp.get_magic()
yep, will create a pr