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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff B005, B015, B032 and fix occurrences #113543

Merged
merged 8 commits into from
Mar 16, 2024

Conversation

autinerd
Copy link
Contributor

@autinerd autinerd commented Mar 15, 2024

Proposed change

This adds the following Ruff rules and fixes the occurrences in the codebase:

  • B005: Using .strip() with multi-character strings is misleading
  • B015: Pointless comparison. Did you mean to assign a value? Otherwise, prepend assert or remove it.
    Quite some tests had comparisons without assert, which are pointless.
  • B027: {name} is an empty method in an abstract base class, but has no abstract decorator
  • B032: Possible unintentional type annotation (using :). Did you mean to assign (using =)?

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)
  • Deprecation (breaking change to happen in the future)
  • 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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

jbouwh
jbouwh previously approved these changes Mar 15, 2024
Copy link
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

LGTM,
Thnx @autinerd 👍

@jbouwh jbouwh dismissed their stale review March 15, 2024 19:25

mypy issue

Comment on lines 51 to 57
@abstractmethod
async def async_reload(self, language: str | None = None) -> None:
"""Clear cached intents for a language."""

@abstractmethod
async def async_prepare(self, language: str | None = None) -> None:
"""Load intents for a language."""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, these two functions are only implemented by DefaultAgent, but no other of the Agent classes. I will revert this rule for now because fixing this would need more work.

@autinerd autinerd changed the title Add ruff B005, B015, B027, B032 and fix occurrences Add ruff B005, B015, B032 and fix occurrences Mar 15, 2024
@autinerd
Copy link
Contributor Author

Oh, quite some tests are failing because of the "new" asserts. Will have to look into them.

@autinerd autinerd marked this pull request as draft March 15, 2024 20:33
@jbouwh
Copy link
Contributor

jbouwh commented Mar 15, 2024

I'll have a look at the mqtt siren test issues

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
@jbouwh
Copy link
Contributor

jbouwh commented Mar 15, 2024

You need to fix the merge conflict

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
@autinerd autinerd marked this pull request as ready for review March 15, 2024 21:56
@autinerd
Copy link
Contributor Author

Hmm, I don't know why this test fails, on my machine the hassio tests pass.

@jbouwh
Copy link
Contributor

jbouwh commented Mar 15, 2024

Hmm, I don't know why this test fails, on my machine the hassio tests pass.

I had the same. I'll have a closer look.

@bdraco
Copy link
Member

bdraco commented Mar 15, 2024

I expect the 0.1 in with patch("homeassistant.components.hassio.issues.REQUEST_REFRESH_DELAY", new=0.1): isn't long enough if the system is otherwise slow

Maybe try 0.2

@jbouwh
Copy link
Contributor

jbouwh commented Mar 16, 2024

I expect the 0.1 in with patch("homeassistant.components.hassio.issues.REQUEST_REFRESH_DELAY", new=0.1): isn't long enough if the system is otherwise slow

Maybe try 0.2

#113569

@bdraco
Copy link
Member

bdraco commented Mar 16, 2024

I expect the 0.1 in with patch("homeassistant.components.hassio.issues.REQUEST_REFRESH_DELAY", new=0.1): isn't long enough if the system is otherwise slow
Maybe try 0.2

#113569

Yeah thats a much better fix 👍

@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Mar 16, 2024
Copy link
Contributor

@jbouwh jbouwh left a comment

Choose a reason for hiding this comment

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

LGTM,
Thnx @autinerd 👍

@bdraco bdraco merged commit 27e844e into home-assistant:dev Mar 16, 2024
35 checks passed
@bdraco bdraco removed the smash Indicator this PR is close to finish for merging or closing label Mar 16, 2024
@autinerd autinerd deleted the ruff-b005 branch March 16, 2024 07:10
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants