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

Pylint Issues with Common Variables in PyScript for Home Assistant #689

Open
Kibukx opened this issue Jan 23, 2025 · 1 comment
Open

Pylint Issues with Common Variables in PyScript for Home Assistant #689

Kibukx opened this issue Jan 23, 2025 · 1 comment

Comments

@Kibukx
Copy link

Kibukx commented Jan 23, 2025

I'm encountering issues with Pylint when using PyScript for Home Assistant, particularly with variables like state, timer, task, and log. These variables are frequently used in PyScript but seem to conflict with Pylint's expectations, causing warnings.

For example, here are a few snippets from my code:

climate.turn_on(entity_id=self.config.entity)
timer.start(entity_id=self.config.on_timer)
def _get_state(self, entity: str) -> str:
    """Gets the state of the specified entity."""
    entity_state = state.get(entity)  # type: ignore
    if entity_state is None:
        self.room.log_state(f"Entity {entity} not found", False)
        return ""
    self.room.log_state(f"State of {entity}: {entity_state}", True)
    return entity_state

Currently, I have to add # type: ignore comments in several places to suppress warnings in my IDE (VS Code). While this works as a temporary fix, it's not ideal, and I’d like to avoid completely disabling the Pylint rule that flags these issues.

Since I’m relatively new to Python, I’m wondering if there’s a more appropriate way to structure or annotate my code to resolve this. Could you provide any guidance on how to handle these Pylint warnings while maintaining clean and functional code?

Thanks in advance for your help!

@IgnusG
Copy link
Contributor

IgnusG commented Jan 24, 2025

Hey @Kibukx 👋 You might be interested in checking out https://github.com/dmamelin/pyscript_autocomplete.

I myself use an adjusted version of https://github.com/dmamelin/pyscript_autocomplete/blob/main/apps/pyscript_autocomplete/pyscript_builtins.py. Think you can just drop it in your code and change the extension to pyi. When you import this into your scripts pylint should pick up the relevant types.

Or if you want type checking/autocomplete for your sensors too (eg. if you have a curtain like cover.living_room_curtain) you can follow the instructions in that repo and install it as a pyscript app. When you run its service it will generate types for your sensors (it will generate these on your home assistant instance so depending on your setup you might have to copy the generated types files from home assistant into your local workspace).

You can search for autocomplete in the issues/discussions for some other threads related to typing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants