ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
794 stars 46 forks source link

PYTHONHUNTER="Q(module='os')" is not working as expected in python2 #77

Closed ctrngk closed 4 years ago

ctrngk commented 4 years ago

Hi,

I evaluate legacy codes in python2 but it is not working as expected

demo.py is as follows

import os
result = os.path.join("/etc", "networks")
print(result)

works in python3

PYTHONHUNTER="Q(module='os')" python3 demo.py

not in python2

PYTHONHUNTER="Q(module='os')" python2 demo.py

Regards,

ionelmc commented 4 years ago

I suspect you want to actually trace os.path instead yes? The problem is that os.path is aliased to ntpath or posixpath depending on platform at runtime (when you import os) so there's little that hunter can do for that, safely that is.

Would this solve the problem for you?

 PYTHONHUNTER='Q(module="os")|Q(module="ntpath")|Q(module="posixpath")' python...