pip: Invalid values in boolean options in the environment cause traceback
Environment
- pip version: 10.0.1
- Python version: 3.6.6
- OS: Debian Unstable
Description
When setting an environment variable that is supposed to hold a boolean value to an invalid string that is not empty, a traceback happens.
Expected behavior
An error message along the lines of "‘blah’ is not a valid value for …, valid values
How to Reproduce
pip install pip==10.0.1
- Run
env PIP_REQUIRE_VIRTUALENV='blah' PYTHONPATH=src python -m pip install twisted
- Observe a traceback
Output
$ env PIP_REQUIRE_VIRTUALENV='blah' PYTHONPATH=src python -m pip install twisted
Traceback (most recent call last):
File "/home/moshez/.pyenv/versions/3.6.4/lib/python3.6/runpy.py", line 193, in
_run_module_as_main
...
values = self.get_default_values()
File "/home/moshez/src/pip/src/pip/_internal/baseparser.py", line 230, in get_default_values
defaults = self._update_defaults(self.defaults.copy()) # ours
File "/home/moshez/src/pip/src/pip/_internal/baseparser.py", line 195, in _update_defaults
val = strtobool(val)
File "/home/moshez/.pyenv/versions/3.6.4/lib/python3.6/distutils/util.py", line 317, in strtobool
raise ValueError("invalid truth value %r" % (val,))
ValueError: invalid truth value 'blah'
Note
The documentation of strtobool
(seen in the traceback above) says:
“True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. Raises ValueError if val is anything else.”
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (14 by maintainers)
I agree, I’d error out if the user gives an incorrect value.