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

String enum values not recognized (false positive invalid-str-returned) #3649

Closed
ppentchev opened this issue May 27, 2020 · 2 comments
Closed
Labels
Milestone

Comments

@ppentchev
Copy link

Steps to reproduce

  1. Run pylint on the attached xenum.py file.
  2. Wonder why it says that the returned value is not a string even for the classes that explicitly subclass "str" before "Enum" and regardless of the isinstance assertion that's good enough for mypy. (now why would mypy need the assertion even for the classes that explicitly subclass str before Enum is a completely different topic for a completely different venue)

Current behavior

E0307: __str__ does not return str (invalid-str-returned) reported for all four methods.

Expected behavior

Nothing reported at all.

pylint --version output

pylint 2.5.2
astroid 2.4.1
Python 3.8.3 (default, May 26 2020, 08:47:10)
[GCC 9.3.0]
xenum-py.txt

@Snawoot
Copy link

Snawoot commented Jun 9, 2020

I also have this issue. Code:

class LogLevel(enum.IntEnum):
    debug = logging.DEBUG
    info = logging.INFO
    warn = logging.WARN
    error = logging.ERROR
    fatal = logging.FATAL
    crit = logging.CRITICAL

    def __str__(self):
        return self.name

Snawoot added a commit to Snawoot/postfix-mta-sts-resolver that referenced this issue Jun 9, 2020
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Aug 8, 2021
@Pierre-Sassoulas
Copy link
Member

Closing because it's been fixed in the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants