[Python-projects] Supress checknig of imported module?

Huurne, Maarten ter maarten.ter.huurne at philips.com
Fri Nov 21 17:59:32 CET 2008


> I had a similar problem with an EnumerationType abstract base class
> written or adapted by a colleague, where each subclass was defined:
>
> class MyEnum(EnumerationType):
>     pass
> MyEnum.initialize('YES', 'NO', 'MAYBE')
>
> and subsequent code could use MyEnum.YES, MyEnum.NO and MyEnum.MAYBE
> These trigger a __hasattr__() call which returns the integer value.

We're using a very similar approach :)

class ResultCode(Enum):
        values = 'ok', 'cancelled', 'warning', 'error', 'inspect'

To work around E1101 warnings, I listed all known enumerations in our code base after "ignored-classes=". This works, but is a bit of a pain to maintain. It would be a lot easier if I could declare that everything that inherits from Enum uses dynamic attributes and does not have to be checked for E1101.

Ideally, this could be declared on the Enum class itself, but at the moment pylint handles suppressions by scope (line numbers, actually) and does not look at inheritance. But being able to write "ignored-classes=Enum" in pylintrc would be almost as good.

Are there likely situations in which inheritance of E1101 is not wanted?

> Of course this also raises the question whether it is possible to
> code something like the following:
>
> if pylint:
>     create/import dummy code
> else:
>     create/import real code

The "if pylint:" part could be done by looking for pylint packages in sys.modules, but having two versions of the code is not nice.

Bye,
                Maarten


The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.


More information about the Python-Projects mailing list