You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Ruff and Basedpyright linters to (the newer) Python scripts in Mbed (#520)
* Add Ruff linter for Python scripts
* Add to CI
* Linting done!
* Add basedpyright and start making fixes
* More basedpyright progress
* Passing pyright!
* Fix a few more errors
* Use types stubs
* Eh just ignore for now
* Tests and linting passing (locally!)
* Pin typing extensions version
* Augh, --unsafe-fixes got rid of my print statements! Dude!
* Reformat
* Muh print statements!!11!1
* Fix cast
* Reformat
* Respond to comments
* Fix comment
'Q000', # bad-quotes-inline-string - Allow using single or double quotes
178
+
'D200', # unnecessary-multiline-docstring
179
+
'RET505', # superfluous-else-return
180
+
'RET506', # superfluous-else-raise
181
+
'TRY003', # raise-vanilla-args - Redundant with EM101
182
+
'COM812', # missing-trailing-comma - incompatible with formatter
183
+
'ISC001', # single-line-implicit-string-concatenation - incompatible with formatter
184
+
'TRY300', # try-consider-else
185
+
'PLR2004', # magic-value-comparison
186
+
'SIM102', # collapsible-if - Sometimes it's nice for readability
187
+
'PERF203', # try-except-in-loop - Sometimes this is needed!
188
+
'PERF401', # manual-list-comprehension - Sometimes this makes code easier to understand.
189
+
'PLR5501', # collapsible-else-if - Stop collapsing my if statements!
190
+
'TC006', # runtime-cast-value
191
+
'G004', # logging-f-string
192
+
'ANN401', # any-type
193
+
'DTZ005', # call-datetime-now-without-tzinfo - If this lint is enabled, it seems difficult to actually work with datetime objects that should be in the local time zone.
194
+
'S701', # jinja2-autoescape-false - autoescape not needed because we are not rendering HTML
195
+
'BLE001', # blind-except
196
+
'S603', # subprocess-without-shell-equals-true - without disabling this, subprocess cannot be used at all!
197
+
'ERA001', # commented-out-code
198
+
'T201', # print
199
+
200
+
# For now allow old-style type annotations. Currently there's lots of code that uses them, and I am
201
+
# not sure if there is a way to upgrade them automatically. And since this project still supports
202
+
# back to Python 3.8, you can't actually use the new style of annotations without using the future annotations feature.
203
+
"FA100", # future-rewritable-type-annotation
204
+
"UP045", # non-pep604-annotation-optional
205
+
"UP006", # non-pep585-annotation
206
+
"UP007"# non-pep604-annotation-union
207
+
]
208
+
209
+
# Allow "unsafe" fixes to be done automatically for the following:
210
+
extend-safe-fixes = [
211
+
"W291", # trailing-whitespace
212
+
"W293", # blank-line-with-whitespace
213
+
"EM101", # raw-string-in-exception
214
+
"TC001", # typing-only-first-party-import
215
+
"TC003", # typing-only-standard-library-import
216
+
]
217
+
218
+
[tool.ruff.lint.mccabe]
219
+
max-complexity = 15
220
+
221
+
[tool.ruff.lint.pylint]
222
+
max-args = 10
223
+
224
+
[tool.ruff.lint.flake8-annotations]
225
+
# Don't require a return type annotation for __init__ in most cases
226
+
mypy-init-return = true
227
+
228
+
[tool.ruff.lint.isort]
229
+
# Still fold imports onto one line if possible, even if the last import ends with a comma
230
+
split-on-trailing-comma = false
231
+
232
+
[tool.basedpyright]
233
+
234
+
# Don't warn about things deprecated more recently than python 3.8
235
+
pythonVersion = "3.8"
236
+
237
+
include = [
238
+
"python/mbed_tools/**",
239
+
"python/mbed_platformio/**"
240
+
]
241
+
242
+
# For right now, we can configure basedpyright in relatively permissive mode.
243
+
# We will allow code where the types of things are partially unknown, as there is
244
+
# lots of legacy code in that category.
245
+
# Also the PlatformIO code has to work with SCons, which is fundamentally type
246
+
# annotation proof, so it can likely never pass these checks.
247
+
reportUnknownVariableType = false
248
+
reportUnknownMemberType = false
249
+
reportUnknownLambdaType = false
250
+
reportMissingTypeArgument = false
251
+
reportUnknownArgumentType = false
252
+
reportUnknownParameterType = false
253
+
reportAny = false
254
+
reportExplicitAny = false
255
+
reportMissingTypeStubs = false
256
+
257
+
# Use "medium strict" member variable annotation rules, where the type checker
258
+
# is allowed to infer the types of class variables based on what gets assigned in __init__
259
+
reportIncompatibleUnannotatedOverride = true
260
+
reportUnannotatedClassAttribute = false
261
+
262
+
# Conflicts with Ruff rules
263
+
reportImplicitStringConcatenation = false
264
+
265
+
# Allow isinstance() even when it seems unneccessary based on type annotations.
266
+
# This call is useful to check that the runtime types match the annotations.
267
+
reportUnnecessaryIsInstance = false
268
+
269
+
# Some ignore comments are only needed on specific platforms, so failing due to unneeded ignore
0 commit comments