Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace in-place lists with tuples (1) #53684

Closed
wants to merge 2 commits into from

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Jul 29, 2021

Proposed change

Followup to #53147
Replace in-place defined lists with tuples.

Example

# old
if state.state in [STATE_CLOSED, STATE_CLOSING]:
    ...

# new
if state.state in (STATE_CLOSED, STATE_CLOSING):
    ...

A check for it will be included with the next pylint release: pylint-dev/pylint#4768

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@@ -81,7 +81,7 @@ async def async_setup(hass, config):
options = {}
mode = conf.get(CONF_MODE, MODE_ROUTER)
for name, value in conf.items():
if name in ([CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]):
if name in (CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not be consistent? There are tuples ending with , and not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat special. The parentheses here weren't used before, i.e.

([CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP])  == [CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]

There wasn't a trailing comma, so no tuple.

Take a look at the next line as well: if name == CONF_REQUIRE_IP .... That suggests that it should only be a normal list / tuple. Not a tuple of tuples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I took this as an example (bad one), but it's still mixed and matched everywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You normally don't need a trailing comma for tuples. Only if there is just one value.

I won't recommend adding additional once either as this would change the formatting with black.

Copy link
Member

@thecode thecode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes for Shelly looks OK

Dev automation moved this from Needs review to Reviewer approved Jul 29, 2021
Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok for deconz

Copy link
Contributor

@cgtobi cgtobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for Kodi and Sonos

Copy link
Member

@bieniu bieniu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for Braother and BraviaTV.

@@ -180,7 +180,7 @@ def __init__(self, name, device, entry, unique_id, coordinator):
self._min_humidity = 30
self._max_humidity = 80
self._humidity_steps = 10
elif self._model in [MODEL_AIRHUMIDIFIER_CA4]:
elif self._model in (MODEL_AIRHUMIDIFIER_CA4,):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better:

elif self._model == MODEL_AIRHUMIDIFIER_CA4:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bieniu The focus for this PR was to only replace lists with tuples. It doesn't really make sense to change one or two more these into equality checks. I might consider adding another pylint check for it to replace all of them at once.

Copy link
Contributor

@elupus elupus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good from philips_js

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤 for rachio, recorder, sonos, and tado

Copy link
Contributor

@pavoni pavoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for roon

Copy link
Contributor

@raman325 raman325 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zwave looks good 馃憤馃従

Copy link
Contributor

@chemelli74 chemelli74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT for Shelly

@samueltardieu
Copy link
Contributor

As I wrote in #53686 (comment), I think the right change would be to use sets for lookups instead of lists or tuples. Those are designed and tuned precisely for this usage.

@cdce8p
Copy link
Member Author

cdce8p commented Jul 30, 2021

As I wrote in #53686 (comment), I think the right change would be to use sets for lookups instead of lists or tuples. Those are designed and tuned precisely for this usage.

I disagree with that. As performance wise, there is no real world difference, using tuples everywhere will make it easier for beginners to understand when to use them. For my full argument see: pylint-dev/pylint#4776 (comment)

@cdce8p cdce8p marked this pull request as draft July 30, 2021 11:05
@cdce8p
Copy link
Member Author

cdce8p commented Aug 12, 2021

Closing this after discussion in pylint-dev/pylint#4776

@cdce8p cdce8p closed this Aug 12, 2021
Dev automation moved this from Reviewer approved to Cancelled Aug 12, 2021
@cdce8p cdce8p deleted the cs_tuple-1 branch August 12, 2021 20:18
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Cancelled
Development

Successfully merging this pull request may close these issues.

None yet