Skip to content

E1507 (invalid-envvar-value) does not accept builtins.str as a valid type for os.getenv argument #5091

Open
@CCardosoDev

Description

@CCardosoDev

Bug description

If the input argument of os.getenv is of type builtins.str pylint complains with the error message os.getenv does not support builtins.str type argument (invalid-envvar-value). This should not be the case since builtins.str is a string. Which is the expected type like mentioned here: "Env manipulation functions support only string type arguments.".

This happens when the key value of the environment variable comes from a data class attribute. Example:

import os
from dataclasses import dataclass
from typing import Optional


@dataclass
class EnvVar:
    """Environment variable to be set."""

    name: str
    _initial_value: Optional[str] = None

    def __post_init__(self):
        """Save current env var value in `self._initial_value`."""

        self._initial_value = os.getenv(self.name)

And the warning is related to os.getenv(self.name).

Command used

pylint env.py

Pylint output

env.py:11:30 E1507 os.getenv does not support builtins.str type argument (invalid-envvar-value)

Expected behavior

No warning raised when the input argument of os.getenv is builtins.str.

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.9.4

OS / Environment

mascOS Big Sur (Versin 11.5.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds decision 🔒Needs a decision before implemention or rejection

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions