Conversation
JonasVautherin
left a comment
There was a problem hiding this comment.
Again those are generated files, see e.g. here.
# -*- coding: utf-8 -*-
# DO NOT EDIT! This file is auto-generated from
# https://github.com/mavlink/MAVSDK-Python/tree/main/other/templates/py
|
We can postprocess generation with ruff check like:
Or we could have done that rewriting in: |
Sure, that's not the problem. I'm merely noting that if you want to contribute, you need to contribute to the templates, not to the generated code that says Respectfully, I can also run a linter. What takes time is to actually contribute the change and then test it. I would be happy to review changes to the templates, given that they are tested. If I need to do most of the work (changing the code and/or testing it), then I'm less enthusiastic 😇. |
|
Understood. Closing. |
Remove the function call overhead of repeatedly calling
list.append().%
ruff check --select=PERF --output-format=concise%
ruff rule PERF401manual-list-comprehension (PERF401)
Derived from the Perflint linter.
Fix is sometimes available.
What it does
Checks for
forloops that can be replaced by a list comprehension.Why is this bad?
When creating a transformed list from an existing list using a for-loop,
prefer a list comprehension. List comprehensions are more readable and
more performant.
Using the below as an example, the list comprehension is ~10% faster on
Python 3.11, and ~25% faster on Python 3.10.
Note that, as with all
perflintrules, this is only intended as amicro-optimization, and will have a negligible impact on performance in
most cases.
Example
Use instead:
If you're appending to an existing list, use the
extendmethod instead: