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="stdlib=False,Q(filename_contains='venv')" is invalid #89

Open abitrolly opened 3 years ago

abitrolly commented 3 years ago

Running a script with PYTHONHUNTER="stdlib=False,Q(filename_contains='venv')" python a_script.py produces this error.

Failed to load hunter from PYTHONHUNTER environ variable "stdlib=False,Q(filename_contains='venv')": SyntaxError('positional argument follows keyword argument', ('<string>', 1, 47, "trace(stdlib=False,Q(filename_contains='venv'))"))
Failed to load hunter from PYTHONHUNTER environ variable "stdlib=False,Q(filename_contains='venv')": SyntaxError('positional argument follows keyword argument', ('<string>', 1, 47, "trace(stdlib=False,Q(filename_contains='venv'))"))
ionelmc commented 3 years ago

Unfortunately hunter doesn't have a custom parser, it just uses python. Therefore you must obey python syntax - you can't give a positional argument after a keyword one. Try Q(filename_contains='venv'),stdlib=False instead.

abitrolly commented 3 years ago

Do you mean it uses some kind of Python eval to parse the string as function argument?

ionelmc commented 3 years ago

Yeeep.

ionelmc commented 3 years ago

Maybe in the future there will be a fancy parser but it's a big feature.

abitrolly commented 3 years ago

Strange that Python doesn't ship with some basic parser lib that allows to detect pair braces and stuff.