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

Issues with new Union Syntax #8119

Closed
cdce8p opened this issue Jan 27, 2023 · 0 comments · Fixed by #8122
Closed

Issues with new Union Syntax #8119

cdce8p opened this issue Jan 27, 2023 · 0 comments · Fixed by #8122
Assignees
Labels
Astroid Related to astroid Blocker 🙅 Blocks the next release python 3.10
Milestone

Comments

@cdce8p
Copy link
Member

cdce8p commented Jan 27, 2023

Bug description

Home Assistant dropped Python 3.9 this week. While upgrading all runtime annotations to the new union syntax, I discovered some issues with pylint. It seems astroid doesn't know how to handle these.

# pylint: disable=missing-docstring,too-few-public-methods,line-too-long,useless-suppression
from __future__ import annotations

from typing import Generic, TypeVar

T = TypeVar("T")


class Coordinator(Generic[T]):
    def __init__(self, update_interval=None) -> None:
        self.update_interval = update_interval


class Child(Coordinator[int | str]):  # <-- 'int | str' here seems to be the issue
    def __init__(self) -> None:
        Coordinator.__init__(self, update_interval=2)  # non-parent-init-called

    def _async_update_data(self):
        assert self.update_interval  # access-member-before-definition
        self.update_interval = 1  # attribute-defined-outside-init

Configuration

[MAIN]
load-plugins=
    pylint.extensions.code_style,
    pylint.extensions.typing,
py-version=3.10

[TYPING]
runtime-typing=no

Command used

pylint test.py

Pylint output

test.py:16:8: W0233: __init__ method from a non direct base class 'Coordinator' is called (non-parent-init-called)
test.py:19:15: E0203: Access to member 'update_interval' before its definition line 20 (access-member-before-definition)
test.py:20:8: W0201: Attribute 'update_interval' defined outside __init__ (attribute-defined-outside-init)

Expected behavior

No errors

Pylint version

pylint 2.16.0b1
astroid 2.14.0-dev0
Python 3.11.1

OS / Environment

No response

Additional dependencies

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Blocker 🙅 Blocks the next release python 3.10
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant