pylint, enums, and redefined-variable-type
Hello, I'm using python 3.4.2 and pylint 1.5.2. Pylint is printing a r:redefined-variable-type warning when I use a variable of type enum. The following script demonstrates the problem: from enum import Enum class MyEnum(Enum): Value1 = 1 Value2 = 2 myEnum = MyEnum.Value1 print("my enum is {}".format(myEnum)) # Huh? this line generates # warning R0204: Redefinition of myEnum type from EnumRepro.MyEnum.Value1 to # EnumRepro.MyEnum.Value2 [R:redefined-variable-type] myEnum = MyEnum.Value2 # this generates print("my enum is {}".format(myEnum)) Is this expected? At the moment I'm just disabling R0204 at the code locations that produce the problem ... I'm new to python, so perhaps I'm just doing something dim. Thanks! Eli This e-mail is intended only for the use of the addressees. Any copying, forwarding, printing or other use of this e-mail by persons other than the addressees is not authorized. This e-mail may contain information that is privileged, confidential and exempt from disclosure. If you are not the intended recipient, please notify us immediately by return e-mail (including the original message in your reply) and then delete and discard all copies of the e-mail. Thank you.
Hey Eli, * Tayrien, Eli (HBO) <Eli.Tayrien@hbo.com> [2016-01-11 18:26:20 +0000]:
class MyEnum(Enum): Value1 = 1 Value2 = 2
As an aside: As many mail clients like to mess up the indentation when sending, it's best to use a pastebin or attach a script (if the mailinglist allows attachments) instead of posting it inline.
# Huh? this line generates # warning R0204: Redefinition of myEnum type from EnumRepro.MyEnum.Value1 to # EnumRepro.MyEnum.Value2 [R:redefined-variable-type]
That smells like a pylint bug. I'm guessing astroid (the analysis library behind pylint) or pylint need to handle enums in some special way. FWIW, I also can reproduce it with astroid/pylint from the git repository. I suggest you open an issue at [1] and mention @lmedioni as she added that checker and is probably most familiar with it. Thanks! Florian [1] https://github.com/PyCQA/pylint/issues/new -- http://www.the-compiler.org | me@the-compiler.org (Mail/XMPP) GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc I love long mails! | http://email.is-not-s.ms/
Florian Bruhin <me@the-compiler.org> writes:
As an aside: As many mail clients like to mess up the indentation when sending, it's best to use a pastebin or attach a script (if the mailinglist allows attachments) instead of posting it inline.
Contrariwise, it's not a good idea to post a link to your code. The code should be in the same thread of discussion, available to anyone who later reads that thread. This should not depend on the availability of some ephemeral pastebin item. Instead, post the code inline; but always compose messages as “plain text” to avoid too-clever software messing with your program code. -- \ “I was arrested today for scalping low numbers at the deli. | `\ Sold a number 3 for 28 bucks.” —Steven Wright | _o__) | Ben Finney
participants (3)
-
Ben Finney
-
Florian Bruhin
-
Tayrien, Eli (HBO)