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

Enable local_partial_types for strict typing [mypy] #86409

Merged
merged 1 commit into from Feb 7, 2023

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Jan 23, 2023

Proposed change

At some point local_partial_types will be enabled by default for mypy.
Start by enabling it as part of the strict typing settings.

From the mypy docs:

In mypy, the most common cases for partial types are variables initialized using None, but without explicit Optional annotations. By default, mypy won’t check partial types spanning module top level or class top level. This flag changes the behavior to only allow partial types at local level, therefore it disallows inferring variable type for None from two assignments in different scopes. For example:

from typing import Optional

a = None  # Need type annotation here if using --local-partial-types
b: Optional[int] = None

class Foo:
    bar = None  # Need type annotation here if using --local-partial-types
    baz: Optional[int] = None

    def __init__(self) -> None:
        self.bar = 1

reveal_type(Foo().bar)  # Union[int, None] without --local-partial-types

Note: this option is always implicitly enabled in mypy daemon and will become enabled by default for mypy in a future release.

https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types

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
  • 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.
  • 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:

@home-assistant home-assistant bot added cla-signed code-quality small-pr PRs with less than 30 lines. labels Jan 23, 2023
@cdce8p cdce8p mentioned this pull request Jan 23, 2023
19 tasks
@cdce8p
Copy link
Member Author

cdce8p commented Jan 23, 2023

The mypy issue will be fixed with the next version which hopefully gets released this week 🤞🏻

I could work around it, but that doesn't seem worthwhile. Final like I added in #86410 should be enough. Let's wait for the mypy release.

homeassistant/components/logbook/queries/common.py:38: error:
    Need type annotation for "PSUEDO_EVENT_STATE_CHANGED" (hint: "PSUEDO_EVENT_STATE_CHANGED: <type> | None = ...")  [var-annotated]

PSUEDO_EVENT_STATE_CHANGED: Final = None

@cdce8p cdce8p added the waiting-for-upstream We're waiting for a change upstream label Jan 23, 2023
@cdce8p cdce8p force-pushed the mypy-enable-local-partial-types branch 3 times, most recently from b9e4656 to c1489ef Compare January 30, 2023 16:56
@cdce8p cdce8p force-pushed the mypy-enable-local-partial-types branch 2 times, most recently from 99e73ba to b82b03f Compare February 6, 2023 22:41
@cdce8p cdce8p removed the waiting-for-upstream We're waiting for a change upstream label Feb 7, 2023
@cdce8p cdce8p force-pushed the mypy-enable-local-partial-types branch from b82b03f to 2aebd51 Compare February 7, 2023 01:49
@cdce8p cdce8p marked this pull request as ready for review February 7, 2023 02:02
@cdce8p cdce8p added the smash Indicator this PR is close to finish for merging or closing label Feb 7, 2023
@bdraco bdraco merged commit af59623 into home-assistant:dev Feb 7, 2023
@cdce8p cdce8p deleted the mypy-enable-local-partial-types branch February 7, 2023 02:42
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed code-quality small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants