Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Incompatible os.getenv default value #1669

Closed
renatgalimov opened this issue Sep 20, 2017 · 6 comments
Closed

Check for Incompatible os.getenv default value #1669

renatgalimov opened this issue Sep 20, 2017 · 6 comments
Labels
Enhancement ✨ Improvement to a component Proposal 📨

Comments

@renatgalimov
Copy link
Contributor

renatgalimov commented Sep 20, 2017

Steps to reproduce

  1. echo import os >> test.py
  2. echo 'value = os.getenv("VALUE", [])' >> test.py
  3. pylint test.py -rn

Current behavior

$ pylint test.py -rn

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 8.00/10, +2.00)

Expected behavior

$ pylint test.py -rn
************* Module testcase
W:  2, 0: Incompatible getenv default value (incompatible-getenv-default)

-------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 10.00/10, -2.50)

pylint --version output

pylint 1.7.2, 
astroid 1.5.3
Python 3.5.3 (default, Sep 11 2017, 12:24:31) 
[GCC 5.4.0]

Just a moment ago I caught a bug caused by the wrong usage of os.getenv default. I would be nice to have a check for this.

@rogalski
Copy link
Contributor

rogalski commented Sep 20, 2017

May be generalized to invalid-envvar-value, if implemented, also should be emitted for os.putenv, os.environ.get and os.environ[k] = v assignments.

@PCManticore
Copy link
Contributor

In an ideal world, we would have support for type annotations and type stubs, which would had solved this problem without requiring an extra check, just a new stub for these functions. Until then, we can probably go with this check, as suggested by @rogalski

@PCManticore PCManticore added the Enhancement ✨ Improvement to a component label Sep 21, 2017
@renatgalimov
Copy link
Contributor Author

Thanks. I can do it if nobody already started.

@PCManticore
Copy link
Contributor

Sure thing! Let us know if there is anything we can help with.

@scirelli
Copy link

scirelli commented Dec 4, 2019

Any idea why I'm now seeing

warning| [invalid-envvar-default] os.getenv default type is builtins.int. Expected str or None.

for

    logger = logging.getLogger('Some Name')
    logger.setLevel(getenv('LOGLEVEL', default=logging.NOTSET))

NOTSET is 0
https://docs.python.org/3/library/logging.html#logging-levels

@scirelli
Copy link

scirelli commented Dec 6, 2019

Nm. I read the docs. I see what the warning means. getenv will case the default value to a string. The warning is a little confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Proposal 📨
Projects
None yet
Development

No branches or pull requests

4 participants