question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid values in boolean options in the environment cause traceback

See original GitHub issue

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

  1. pip install pip==10.0.1
  2. Run env PIP_REQUIRE_VIRTUALENV='blah' PYTHONPATH=src python -m pip install twisted
  3. 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:closed
  • Created 5 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
pfmoorecommented, Jul 23, 2018

I agree, I’d error out if the user gives an incorrect value.

0reactions
lock[bot]commented, Jun 2, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found