55
66
77def get_class (module_name , kls ):
8- parts = kls .split ('.' )
8+ parts = kls .split ("." )
99 m = __import__ (module_name )
10- for mp in module_name .split ('.' )[1 :]:
10+ for mp in module_name .split ("." )[1 :]:
1111 m = getattr (m , mp )
1212 klass = getattr (m , parts [0 ])
1313 return klass
1414
1515
1616class NoSuchChecker (Exception ):
17-
1817 def __init__ (self , checker_class ):
1918 self .message = "Checker class %s was not found" % checker_class
2019
@@ -32,18 +31,21 @@ def get_checker(linter: PyLinter, checker_class):
3231def augment_visit (linter : PyLinter , checker_method , augmentation ):
3332 """
3433 Augmenting a visit enables additional errors to be raised (although that case is
35- better served using a new checker) or to suppress all warnings in certain circumstances.
34+ better served using a new checker) or to suppress all warnings in certain
35+ circumstances.
3636
37- Augmenting functions should accept a 'chain' function, which runs the checker method
38- and possibly any other augmentations, and secondly an Astroid node. "chain()" can be
39- called at any point to trigger the continuation of other checks, or not at all to
40- prevent any further checking.
37+ Augmenting functions should accept a 'chain' function, which runs the checker
38+ method and possibly any other augmentations, and secondly an Astroid node.
39+ "chain()" can be called at any point to trigger the continuation of other
40+ checks, or not at all to prevent any further checking.
4141 """
4242
4343 try :
4444 checker = get_checker (linter , checker_method .__self__ .__class__ )
4545 except AttributeError :
46- checker = get_checker (linter , get_class (checker_method .__module__ , checker_method .__qualname__ ))
46+ checker = get_checker (
47+ linter , get_class (checker_method .__module__ , checker_method .__qualname__ )
48+ )
4749
4850 old_method = getattr (checker , checker_method .__name__ )
4951 setattr (checker , checker_method .__name__ , AugmentFunc (old_method , augmentation ))
@@ -68,7 +70,6 @@ def __call__(self):
6870
6971
7072class Suppress :
71-
7273 def __init__ (self , linter ):
7374 self ._linter = linter
7475 self ._suppress = []
@@ -89,13 +90,6 @@ def suppress(self, *symbols):
8990 def __exit__ (self , exc_type , exc_val , exc_tb ):
9091 self ._linter .add_message = self ._orig_add_message
9192 for to_append_args , to_append_kwargs in self ._messages_to_append :
92- # Depending on the Pylint version, the add_message API is different.
93- # Either a single object called 'message' is passed, or the first argument
94- # is a message symbol.
95- if hasattr ('symbol' , to_append_args [0 ]):
96- code = to_append_args [0 ].symbol
97- else :
98- code = to_append_args [0 ]
9993 if to_append_args [0 ] in self ._suppress :
10094 continue
10195 self ._linter .add_message (* to_append_args , ** to_append_kwargs )
@@ -107,7 +101,9 @@ def suppress_message(linter: PyLinter, checker_method, message_id_or_symbol, tes
107101 returns True. It is useful to prevent one particular message from being raised
108102 in one particular case, while leaving the rest of the messages intact.
109103 """
110- augment_visit (linter , checker_method , DoSuppress (linter , message_id_or_symbol , test_func ))
104+ augment_visit (
105+ linter , checker_method , DoSuppress (linter , message_id_or_symbol , test_func )
106+ )
111107
112108
113109class DoSuppress :
@@ -124,40 +120,49 @@ def __call__(self, chain, node):
124120
125121 @property
126122 def symbols (self ) -> List :
127- # At some point, pylint started preferring message symbols to message IDs. However this is not done
128- # consistently or uniformly - occasionally there are some message IDs with no matching symbols.
129- # We try to work around this here by suppressing both the ID and the symbol, if we can find it.
123+ # At some point, pylint started preferring message symbols to message IDs.
124+ # However, this is not done consistently or uniformly
125+ # - occasionally there are some message IDs with no matching symbols.
126+ # We try to work around this here by suppressing both the ID and the symbol.
130127 # This also gives us compatability with a broader range of pylint versions.
131128
132- # Similarly, a commit between version 1.2 and 1.3 changed where the messages are stored - see:
133- # https://bitbucket.org/logilab/pylint/commits/0b67f42799bed08aebb47babdc9fb0e761efc4ff#chg-reporters/__init__.py
134- # Therefore here, we try the new attribute name, and fall back to the old version for
135- # compatability with <=1.2 and >=1.3
129+ # Similarly, between version 1.2 and 1.3 changed where the messages are stored
130+ # - see:
131+ # https://bitbucket.org/logilab/pylint/commits/0b67f42799bed08aebb47babdc9fb0e761efc4ff#chg-reporters/__init__.py
132+ # Therefore here, we try the new attribute name, and fall back to the old
133+ # version for compatability with <=1.2 and >=1.3
136134
137135 try :
138136 pylint_messages = self .get_message_definitions (self .message_id_or_symbol )
139- the_symbols = [symbol
140- for pylint_message in pylint_messages
141- for symbol in (pylint_message .msgid , pylint_message .symbol )
142- if symbol is not None ]
137+ the_symbols = [
138+ symbol
139+ for pylint_message in pylint_messages
140+ for symbol in (pylint_message .msgid , pylint_message .symbol )
141+ if symbol is not None
142+ ]
143143 except UnknownMessageError :
144- # This can happen due to mismatches of pylint versions and plugin expectations of available messages
144+ # This can happen due to mismatches of pylint versions and plugin
145+ # expectations of available messages
145146 the_symbols = [self .message_id_or_symbol ]
146147
147148 return the_symbols
148149
149150 def get_message_definitions (self , message_id_or_symbol ):
150- msgs_store = getattr (self .linter , ' msgs_store' , self .linter )
151+ msgs_store = getattr (self .linter , " msgs_store" , self .linter )
151152
152- if hasattr (msgs_store , ' check_message_id' ):
153+ if hasattr (msgs_store , " check_message_id" ):
153154 return [msgs_store .check_message_id (message_id_or_symbol )]
154155 # pylint 2.0 renamed check_message_id to get_message_definition in:
155156 # https://github.com/PyCQA/pylint/commit/5ccbf9eaa54c0c302c9180bdfb745566c16e416d
156- elif hasattr (msgs_store , ' get_message_definition' ):
157+ elif hasattr (msgs_store , " get_message_definition" ):
157158 return [msgs_store .get_message_definition (message_id_or_symbol )]
158159 # pylint 2.3.0 renamed get_message_definition to get_message_definitions in:
159160 # https://github.com/PyCQA/pylint/commit/da67a9da682e51844fbc674229ff6619eb9c816a
160- elif hasattr (msgs_store , ' get_message_definitions' ):
161+ elif hasattr (msgs_store , " get_message_definitions" ):
161162 return msgs_store .get_message_definitions (message_id_or_symbol )
162163 else :
163- raise ValueError ('pylint.utils.MessagesStore does not have a get_message_definition(s) method' )
164+ msg = (
165+ "pylint.utils.MessagesStore does not have a "
166+ "get_message_definition(s) method"
167+ )
168+ raise ValueError (msg )
0 commit comments