Invalid values in boolean options in the environment cause traceback
See original GitHub issueEnvironment
- 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.”
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (14 by maintainers)
Top Results From Across the Web
Evaluate boolean environment variable in Python
Option 1. I think this works well: my_env = os.getenv("ENV_VAR", 'False').lower() in ('true', '1', 't').
Read more >Invalid Syntax in Python: Common Reasons for SyntaxError
Python will attempt to help you determine where the invalid syntax is in your code, but the traceback it provides can be a...
Read more >configparser — Configuration file parser — Python 3.11.1 ...
This method is case-insensitive and recognizes Boolean values from 'yes' / 'no' ... every valid value (e.g. section names, options and empty lines...
Read more >The Sharp Bits — JAX documentation
Pure functions#. JAX transformation and compilation are designed to work only on Python functions that are functionally pure: all the input data is...
Read more >Basic patterns and examples — pytest documentation
pytest: error: argument --cmdopt: invalid choice: 'type3' (choose from 'type1', ... content of conftest.py import pytest def type_checker(value): msg ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree, I’d error out if the user gives an incorrect value.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.