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

fix: type-checking Eve dynamic attrs #1541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raulparada
Copy link

@raulparada raulparada commented Oct 30, 2024

Description

Adding event hooks to an Eve instance produces types errors such as:

Cannot assign to attribute "on_insert_<redacted>" for class "Eve"
  Attribute "on_insert_<redacted>" is unknown. Pylance[reportAttributeAccessIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportAttributeAccessIssue)

by pyright/pylance. The pyright maintainer's advice for such cases is to add a __setattr__ to such classes which allow dynamic attributes. Doing that here. Note it's behind the typing.TYPE_CHECKING guard which makes it have no effect at runtime, thus it only impacts type-checking. I've confirmed this fixes the type errors on pyright.

Why care about pyright?

It's the more correct python type-checker (see official python typing benchmarks). Chances are other type-checkers (most importantly mypy) may not fail on this temporarily only due to their lack of coverage.

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

Successfully merging this pull request may close these issues.

1 participant