Add pylint CodeStyle extension #53147
Merged
+103
−98
Conversation
1 of 21 tasks
1975f29
to
b218fa7
@@ -299,7 +299,7 @@ def _validate_zone_input(zone_input): | |||
errors["base"] = "relay_inclusive" | |||
|
|||
# The following keys must be int | |||
for key in [CONF_ZONE_NUMBER, CONF_ZONE_LOOP, CONF_RELAY_ADDR, CONF_RELAY_CHAN]: | |||
for key in (CONF_ZONE_NUMBER, CONF_ZONE_LOOP, CONF_RELAY_ADDR, CONF_RELAY_CHAN): |
balloob
Jul 19, 2021
Member
I'm surprised this isn't automatically handled by something like pyupgrade
I'm surprised this isn't automatically handled by something like pyupgrade
frenck
Jul 19, 2021
Member
That would indeed be nice!
That would indeed be nice!
cdce8p
Jul 19, 2021
Author
Member
That was my first though as well. Unfortunately it got rejected as not being in the "spirit of pyupgrade". Hence I had to implement it in pylint instead. If you like, feel free to leave a comment there: asottile/pyupgrade#458
That was my first though as well. Unfortunately it got rejected as not being in the "spirit of pyupgrade". Hence I had to implement it in pylint instead. If you like, feel free to leave a comment there: asottile/pyupgrade#458
I like this change |
f6b162b
into
home-assistant:dev
30 checks passed
30 checks passed
1 of 21 tasks
raman325
added a commit
to raman325/home-assistant
that referenced
this pull request
Jul 19, 2021
…/home-assistant into climacell_strongly_type * 'climacell_strongly_type' of https://github.com/raman325/home-assistant: (35 commits) Upgrade holidays to 0.11.2 (home-assistant#53191) Upgrade numpy to 1.21.1 (home-assistant#53194) Remove I/O in Plex tests (home-assistant#53196) Upgrade black to 21.7b0 (home-assistant#53192) Use entity class attributes for Citybikes (home-assistant#53167) Modify AirVisual states to be translatable (home-assistant#53133) Activate mypy in aurora (home-assistant#53150) Use entity class attributes for avea (home-assistant#52695) Correct typing in azure_devops and activate mypy (home-assistant#53152) Bugfix current temperature in gree climate (home-assistant#53149) Add pylint CodeStyle extension (home-assistant#53147) Add sound pressure unit constants (dB + dBa) (home-assistant#53159) Add Switcher config flow discovery support (home-assistant#52316) Correct typing in control4 and activate mypy (home-assistant#53156) Activate mypy for eafm (home-assistant#53184) Allow pymodbus to reconnect in running system (not startup) (home-assistant#53020) Bump zeroconf to 0.33.1 (home-assistant#53179) Execute scripts from HomeKit (home-assistant#53106) Cleanup redundant coveragerc entries (home-assistant#53171) Run pyupgrade on homekit config_flow (home-assistant#53180) ...
1 of 12 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Proposed change
Pylint 2.9 added a new optional extension:
CodeStyle
checker. Those checks don't necessarily provide performance improvements or catch errors, but instead are useful for code consistency and quality.Currently, there are two checks:
consider-using-tuple
: In-place defined lists infor
loops andif
clauses can almost always be replaced by tuples.consider-using-namedtuple-or-dataclass
: Emitted if dict values can be replaced by aNamedTuple
ordataclass
. Especially useful for sensor definitions. Currently they are mostly handled like the example frommetoffice/sensor.py
below: each sensor has a dict entry and the attributes are captured in a list or tuple. Later they are accessed via index lookup which is prone to errors, difficult to understand, and nearly impossible to type check. At least, the example has a comment explaining the individual fields but that isn't the norm.core/homeassistant/components/metoffice/sensor.py
Lines 37 to 48 in 71a8ae3
In contrast, this is how it could look like:
core/homeassistant/components/huawei_lte/sensor.py
Lines 48 to 67 in 71a8ae3
As there are quite a lot of components that use lists, I had to disable the check for now. If the PR is accepted, I plan to open a tracking that enables the check. After that each component that uses the old style would need to be updated, preferable by the code-owner in a separate PR.
Links
http://pylint.pycqa.org/en/latest/whatsnew/2.9.html
http://pylint.pycqa.org/en/latest/technical_reference/extensions.html#pylint-extensions-code-style
--
/CC: @frenck
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: