57
57
Options ,
58
58
)
59
59
from pylint .utils import ASTWalker , FileState , LinterStats , utils
60
- from pylint .utils .pragma_parser import (
61
- OPTION_PO ,
62
- InvalidPragmaError ,
63
- UnRecognizedOptionError ,
64
- parse_pragma ,
65
- )
66
60
67
61
if sys .version_info >= (3 , 8 ):
68
62
from typing import Protocol
@@ -226,7 +220,7 @@ class PyLinter(
226
220
_ArgumentsManager ,
227
221
_MessageStateHandler ,
228
222
reporters .ReportsHandlerMixIn ,
229
- checkers .BaseTokenChecker ,
223
+ checkers .BaseChecker ,
230
224
):
231
225
"""Lint Python modules using external checkers.
232
226
@@ -290,7 +284,6 @@ def __init__(
290
284
self .current_name : str | None = None
291
285
self .current_file : str | None = None
292
286
self ._ignore_file = False
293
- self ._pragma_lineno : dict [str , int ] = {}
294
287
295
288
# Attributes related to stats
296
289
self .stats = LinterStats ()
@@ -307,13 +300,13 @@ def __init__(
307
300
"""List of message symbols on which pylint should fail, set by --fail-on."""
308
301
self ._error_mode = False
309
302
310
- # Attributes related to messages (states) and their handling
303
+ # Attributes related to registering messages and their handling
311
304
self .msgs_store = MessageDefinitionStore ()
312
305
self .msg_status = 0
313
306
self ._by_id_managed_msgs : list [ManagedMessage ] = []
314
307
315
308
reporters .ReportsHandlerMixIn .__init__ (self )
316
- checkers .BaseTokenChecker .__init__ (self , self )
309
+ checkers .BaseChecker .__init__ (self , self )
317
310
# provided reports
318
311
self .reports = (
319
312
("RP0001" , "Messages by category" , report_total_messages_stats ),
@@ -508,91 +501,6 @@ def _parse_error_mode(self) -> None:
508
501
self .set_option ("persistent" , False )
509
502
self .set_option ("score" , False )
510
503
511
- # block level option handling #############################################
512
- # see func_block_disable_msg.py test case for expected behaviour
513
-
514
- def process_tokens (self , tokens : list [tokenize .TokenInfo ]) -> None :
515
- """Process tokens from the current module to search for module/block level
516
- options.
517
- """
518
- control_pragmas = {"disable" , "disable-next" , "enable" }
519
- prev_line = None
520
- saw_newline = True
521
- seen_newline = True
522
- for (tok_type , content , start , _ , _ ) in tokens :
523
- if prev_line and prev_line != start [0 ]:
524
- saw_newline = seen_newline
525
- seen_newline = False
526
-
527
- prev_line = start [0 ]
528
- if tok_type in (tokenize .NL , tokenize .NEWLINE ):
529
- seen_newline = True
530
-
531
- if tok_type != tokenize .COMMENT :
532
- continue
533
- match = OPTION_PO .search (content )
534
- if match is None :
535
- continue
536
- try :
537
- for pragma_repr in parse_pragma (match .group (2 )):
538
- if pragma_repr .action in {"disable-all" , "skip-file" }:
539
- if pragma_repr .action == "disable-all" :
540
- self .add_message (
541
- "deprecated-pragma" ,
542
- line = start [0 ],
543
- args = ("disable-all" , "skip-file" ),
544
- )
545
- self .add_message ("file-ignored" , line = start [0 ])
546
- self ._ignore_file = True
547
- return
548
- try :
549
- meth = self ._options_methods [pragma_repr .action ]
550
- except KeyError :
551
- meth = self ._bw_options_methods [pragma_repr .action ]
552
- # found a "(dis|en)able-msg" pragma deprecated suppression
553
- self .add_message (
554
- "deprecated-pragma" ,
555
- line = start [0 ],
556
- args = (
557
- pragma_repr .action ,
558
- pragma_repr .action .replace ("-msg" , "" ),
559
- ),
560
- )
561
- for msgid in pragma_repr .messages :
562
- # Add the line where a control pragma was encountered.
563
- if pragma_repr .action in control_pragmas :
564
- self ._pragma_lineno [msgid ] = start [0 ]
565
-
566
- if (pragma_repr .action , msgid ) == ("disable" , "all" ):
567
- self .add_message (
568
- "deprecated-pragma" ,
569
- line = start [0 ],
570
- args = ("disable=all" , "skip-file" ),
571
- )
572
- self .add_message ("file-ignored" , line = start [0 ])
573
- self ._ignore_file = True
574
- return
575
- # If we did not see a newline between the previous line and now,
576
- # we saw a backslash so treat the two lines as one.
577
- l_start = start [0 ]
578
- if not saw_newline :
579
- l_start -= 1
580
- try :
581
- meth (msgid , "module" , l_start )
582
- except exceptions .UnknownMessageError :
583
- msg = f"{ pragma_repr .action } . Don't recognize message { msgid } ."
584
- self .add_message (
585
- "bad-option-value" , args = msg , line = start [0 ]
586
- )
587
- except UnRecognizedOptionError as err :
588
- self .add_message (
589
- "unrecognized-inline-option" , args = err .token , line = start [0 ]
590
- )
591
- continue
592
- except InvalidPragmaError as err :
593
- self .add_message ("bad-inline-option" , args = err .token , line = start [0 ])
594
- continue
595
-
596
504
# code checking methods ###################################################
597
505
598
506
def get_checkers (self ) -> list [BaseChecker ]:
@@ -1025,8 +933,7 @@ def _check_astroid_module(
1025
933
self .add_message ("raw-checker-failed" , args = node .name )
1026
934
else :
1027
935
# assert astroid.file.endswith('.py')
1028
- # invoke ITokenChecker interface on self to fetch module/block
1029
- # level options
936
+ # Parse module/block level option pragma's
1030
937
self .process_tokens (tokens )
1031
938
if self ._ignore_file :
1032
939
return False
0 commit comments