From a9eeeee9fe2f6dbf0254553d79f266d1651e97a9 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 24 Apr 2012 16:35:49 +0000 Subject: [PATCH] Remove E1101 errors generated by colorama.AnsiCodes. Pylint fails to parse generated members in a __init__() function. R=cmp@chromium.org BUG= TEST=Manually tested on linux, cygwin and windows Review URL: http://codereview.chromium.org/10202010 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@133705 0039d316-1c4b-4281-b951-d872f2087c98 --- pylintrc | 2 +- third_party/colorama/ansi.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pylintrc b/pylintrc index 0412be85b..296bab032 100644 --- a/pylintrc +++ b/pylintrc @@ -124,7 +124,7 @@ ignore-mixin-members=yes # List of classes names for which member attributes should not be checked # (useful for classes with attributes dynamically set). -ignored-classes=SQLObject,AnsiCodes +ignored-classes=SQLObject # When zope mode is activated, add a predefined set of Zope acquired attributes # to generated-members. diff --git a/third_party/colorama/ansi.py b/third_party/colorama/ansi.py index 7b818e19e..7f09a989e 100644 --- a/third_party/colorama/ansi.py +++ b/third_party/colorama/ansi.py @@ -9,13 +9,14 @@ def code_to_chars(code): return CSI + str(code) + 'm' class AnsiCodes(object): - def __init__(self, codes): - for name in dir(codes): - if not name.startswith('_'): - value = getattr(codes, name) + def __init__(self): + for name in dir(self): + if not name.startswith('_') and name.upper() == name: + value = getattr(self, name) setattr(self, name, code_to_chars(value)) -class AnsiFore: + +class AnsiFore(AnsiCodes): BLACK = 30 RED = 31 GREEN = 32 @@ -26,7 +27,7 @@ class AnsiFore: WHITE = 37 RESET = 39 -class AnsiBack: +class AnsiBack(AnsiCodes): BLACK = 40 RED = 41 GREEN = 42 @@ -37,13 +38,15 @@ class AnsiBack: WHITE = 47 RESET = 49 -class AnsiStyle: +class AnsiStyle(AnsiCodes): BRIGHT = 1 DIM = 2 NORMAL = 22 RESET_ALL = 0 -Fore = AnsiCodes( AnsiFore ) -Back = AnsiCodes( AnsiBack ) -Style = AnsiCodes( AnsiStyle ) +# Constructing the object converts the code into the equivalent ANSI escape +# string. +Fore = AnsiFore() +Back = AnsiBack() +Style = AnsiStyle()