0
# Built-in Checkers
1
2
Comprehensive set of 78+ built-in checkers covering all aspects of Python code analysis. These checkers are automatically loaded and provide extensive static analysis capabilities for variables, imports, formatting, type checking, classes, design patterns, and specialized language features.
3
4
## Capabilities
5
6
### Core Analysis Checkers
7
8
Essential checkers that form the foundation of pylint's static analysis capabilities.
9
10
```python { .api }
11
# Variable analysis
12
import pylint.checkers.variables
13
# - Unused variables and imports
14
# - Undefined variables
15
# - Variable redefinition
16
# - Global variable usage
17
18
# Import analysis
19
import pylint.checkers.imports
20
# - Import order and grouping
21
# - Circular imports
22
# - Unused imports
23
# - Relative import usage
24
25
# Basic code analysis
26
import pylint.checkers.base
27
# - Unreachable code
28
# - Dangerous default arguments
29
# - Lost exception context
30
# - Assert statements on tuples
31
```
32
33
### Code Style and Formatting
34
35
Checkers that enforce coding standards and formatting conventions.
36
37
```python { .api }
38
# Format and style checking
39
import pylint.checkers.format
40
# - Line length limits
41
# - Indentation consistency
42
# - Trailing whitespace
43
# - Blank line usage
44
# - Operator spacing
45
46
# Method and function arguments
47
import pylint.checkers.method_args
48
# - Duplicate argument names
49
# - Missing required arguments
50
# - Keyword argument validation
51
# - *args and **kwargs usage
52
```
53
54
### Type System Analysis
55
56
Advanced type checking and inference validation.
57
58
```python { .api }
59
# Type checking and inference
60
import pylint.checkers.typecheck
61
# - Attribute access validation
62
# - Method call validation
63
# - Type compatibility checking
64
# - Iterator and sequence validation
65
66
# String usage analysis
67
import pylint.checkers.strings
68
# - String formatting validation
69
# - Quote consistency
70
# - String concatenation patterns
71
# - Format string validation
72
```
73
74
### Object-Oriented Programming
75
76
Checkers focused on class definitions, inheritance, and OOP patterns.
77
78
```python { .api }
79
# Class analysis
80
import pylint.checkers.classes
81
# - Method resolution order
82
# - Abstract method implementation
83
# - Class attribute access
84
# - Special method implementation
85
86
# New-style class features
87
import pylint.checkers.newstyle
88
# - Property usage
89
# - Descriptor validation
90
# - Metaclass usage
91
# - Class decoration
92
```
93
94
### Exception Handling
95
96
Analysis of exception handling patterns and error management.
97
98
```python { .api }
99
# Exception handling analysis
100
import pylint.checkers.exceptions
101
# - Bare except clauses
102
# - Exception hierarchy validation
103
# - Exception chaining
104
# - Finally clause usage
105
# - Exception message validation
106
```
107
108
### Design and Architecture
109
110
High-level design analysis and architectural pattern validation.
111
112
```python { .api }
113
# Design analysis
114
import pylint.checkers.design_analysis
115
# - Cyclomatic complexity
116
# - Class coupling metrics
117
# - Method/class size limits
118
# - Inheritance depth analysis
119
# - Interface segregation
120
```
121
122
### Refactoring Suggestions
123
124
Checkers that identify opportunities for code improvement and refactoring.
125
126
```python { .api }
127
# Refactoring opportunities
128
import pylint.checkers.refactoring
129
# - Simplifiable conditions
130
# - Unnecessary loops
131
# - Redundant code patterns
132
# - Boolean expression simplification
133
# - Consider using enumerate/zip
134
```
135
136
### Standard Library Usage
137
138
Validation of Python standard library usage patterns and best practices.
139
140
```python { .api }
141
# Standard library validation
142
import pylint.checkers.stdlib
143
# - Deprecated standard library usage
144
# - Incorrect API usage patterns
145
# - Performance anti-patterns
146
# - Security concerns in stdlib usage
147
```
148
149
### Logging Analysis
150
151
Specialized analysis for logging usage patterns and best practices.
152
153
```python { .api }
154
# Logging usage analysis
155
import pylint.checkers.logging
156
# - Logging format string validation
157
# - Logger configuration checking
158
# - Log level consistency
159
# - Logging performance patterns
160
```
161
162
### Modern Python Features
163
164
Checkers for contemporary Python language features and patterns.
165
166
```python { .api }
167
# Async/await pattern analysis
168
import pylint.checkers.async_
169
# - Async function usage
170
# - Await expression validation
171
# - Async context manager usage
172
# - Async iterator patterns
173
174
# Threading and concurrency
175
import pylint.checkers.threading
176
# - Thread safety analysis
177
# - Lock usage patterns
178
# - Shared state validation
179
# - Race condition detection
180
```
181
182
### Code Quality Metrics
183
184
Specialized checkers for code quality assessment and metrics collection.
185
186
```python { .api }
187
# Unicode and encoding
188
import pylint.checkers.unicode
189
# - Encoding declaration validation
190
# - Unicode string handling
191
# - Character encoding issues
192
193
# Spelling validation
194
import pylint.checkers.spelling
195
# - Comment and docstring spelling
196
# - Variable name spelling
197
# - Configurable dictionaries
198
# - Technical term validation
199
```
200
201
### Similarity Detection
202
203
Detection of code duplication and similar patterns.
204
205
```python { .api }
206
# Code similarity analysis
207
import pylint.checkers.symilar
208
# - Duplicate code detection
209
# - Similar structure identification
210
# - Configurable similarity thresholds
211
# - Cross-file duplication checking
212
```
213
214
## Checker Categories
215
216
### Convention (C) Messages
217
218
Code style and convention violations that don't affect functionality.
219
220
```python { .api }
221
# Examples of convention messages:
222
# C0103: invalid-name - Name doesn't conform to naming convention
223
# C0111: missing-docstring - Missing module/class/function docstring
224
# C0301: line-too-long - Line exceeds maximum length limit
225
# C0326: bad-whitespace - Wrong whitespace usage
226
```
227
228
### Refactor (R) Messages
229
230
Suggestions for code improvements and refactoring opportunities.
231
232
```python { .api }
233
# Examples of refactor messages:
234
# R0201: no-self-use - Method could be a function
235
# R0903: too-few-public-methods - Class has too few public methods
236
# R0913: too-many-arguments - Function has too many arguments
237
# R1705: no-else-return - Unnecessary else after return
238
```
239
240
### Warning (W) Messages
241
242
Potential issues that might cause problems but aren't definite errors.
243
244
```python { .api }
245
# Examples of warning messages:
246
# W0613: unused-argument - Unused function argument
247
# W0622: redefined-builtin - Redefining built-in function
248
# W0703: broad-except - Catching too general exception
249
# W1203: logging-fstring-interpolation - Use lazy % formatting in logging
250
```
251
252
### Error (E) Messages
253
254
Probable bugs and definite code errors.
255
256
```python { .api }
257
# Examples of error messages:
258
# E0601: used-before-assignment - Using variable before assignment
259
# E1101: no-member - Instance has no member
260
# E1120: no-value-for-parameter - No value provided for required parameter
261
# E1136: unsubscriptable-object - Value is not subscriptable
262
```
263
264
### Fatal (F) Messages
265
266
Errors that prevent pylint from continuing analysis.
267
268
```python { .api }
269
# Examples of fatal messages:
270
# F0001: fatal - Error occurred preventing further processing
271
# F0010: error - Error in configuration or parsing
272
# F0202: method-check-failed - Unable to check method signature
273
```
274
275
## Usage Examples
276
277
### Enabling/Disabling Specific Checkers
278
279
```python
280
from pylint.lint import PyLinter
281
282
linter = PyLinter()
283
284
# Disable specific checkers
285
linter.config.disable = ['missing-docstring', 'invalid-name']
286
287
# Enable only specific categories
288
linter.config.disable = 'all'
289
linter.config.enable = ['error', 'fatal']
290
291
# Configure specific checker options
292
linter.config.max_line_length = 120
293
linter.config.good_names = ['i', 'j', 'k', 'x', 'y', 'z']
294
```
295
296
### Programmatic Checker Configuration
297
298
```python
299
# Configure variable naming patterns
300
linter.config.variable_rgx = r'[a-z_][a-z0-9_]{2,30}$'
301
linter.config.const_rgx = r'(([A-Z_][A-Z0-9_]*)|(__.*__))$'
302
linter.config.class_rgx = r'[A-Z_][a-zA-Z0-9]+$'
303
304
# Configure complexity limits
305
linter.config.max_complexity = 10
306
linter.config.max_args = 5
307
linter.config.max_locals = 15
308
linter.config.max_branches = 12
309
310
# Configure import checking
311
linter.config.import_graph = True
312
linter.config.ext_import_graph = True
313
linter.config.int_import_graph = True
314
```
315
316
### Custom Message Filtering
317
318
```python
319
# Filter messages by category
320
def filter_messages(message):
321
# Only show errors and fatals
322
return message.category in ['E', 'F']
323
324
# Filter messages by pattern
325
import re
326
def filter_by_pattern(message):
327
# Skip messages about test files
328
return not re.search(r'test_.*\.py', message.path)
329
```
330
331
## Checker-Specific Configuration
332
333
### Variable Checker Options
334
335
```python
336
# Variable naming and usage configuration
337
variable_rgx = r'[a-z_][a-z0-9_]{2,30}$' # Variable name pattern
338
const_rgx = r'(([A-Z_][A-Z0-9_]*)|(__.*__))$' # Constant pattern
339
good_names = ['i', 'j', 'k', 'x', 'y', 'z'] # Accepted short names
340
bad_names = ['foo', 'bar', 'baz'] # Forbidden names
341
```
342
343
### Import Checker Options
344
345
```python
346
# Import analysis configuration
347
deprecated_modules = ['optparse', 'imp'] # Modules to flag as deprecated
348
import_graph = True # Generate import dependency graph
349
ext_import_graph = True # Include external dependencies
350
preferred_modules = {'collections': 'collections.abc'} # Preferred imports
351
```
352
353
### Format Checker Options
354
355
```python
356
# Code formatting configuration
357
max_line_length = 100 # Maximum line length
358
indent_string = ' ' # Indentation string (4 spaces)
359
indent_after_paren = 4 # Indentation after parenthesis
360
single_line_if_stmt = False # Allow single-line if statements
361
single_line_class_stmt = False # Allow single-line class statements
362
```