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

__slots__ declaration ignored in a subclass of generic collections.abc.AsyncIterator #5099

Closed
dmoklaf opened this issue Oct 1, 2021 · 2 comments
Assignees
Labels
Bug 🪲 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@dmoklaf
Copy link

dmoklaf commented Oct 1, 2021

Bug description

In Python 3.9, as part of the annotation improvements, collections.abc.AsyncIterator has replaced typing.AsyncIterator for annotations.

However, this replacement has broken down pylint for this atiterator.py file (which had no pylint issues before and has no runtime issues):


"Bla bla bla"

import asyncio
import collections
import typing

Type = typing.TypeVar("Type")

# pylint: disable=R0903
class AsyncTimedIterator(collections.abc.AsyncIterator[Type]):
    "Bla bla bla"

    __slots__ = ("_iterator", "_timeout")

    def __init__(
        self, iterator: collections.abc.AsyncIterator[Type], timeout: float
    ) -> None:
        self._iterator = iterator
        self._timeout = timeout

    async def __anext__(self) -> Type:
        return await asyncio.wait_for(self._iterator.__anext__(), self._timeout)

Command used

pylint atiterator.py

Pylint output

************* Module extract
aiterator.py:18:8: E0237: Assigning to attribute '_iterator' not defined in class slots (assigning-non-slot)
aiterator.py:19:8: E0237: Assigning to attribute '_timeout' not defined in class slots (assigning-non-slot)

-------------------------------------------------------------------
Your code has been rated at 0.91/10 (previous run: 10.00/10, -9.09)

Expected behavior

No E0237 warning

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.9.5 (default, May 18 2021, 12:31:01) 
[Clang 10.0.0 ]
MacOS 11.6

OS / Environment

MacOS 11.6
conda 4.10.3
zsh 5.8 (x86_64-apple-darwin20.0)

Additional dependencies

(Available by checking the edition history)

@dmoklaf dmoklaf added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 1, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 25, 2022
@mbyrnepr2 mbyrnepr2 self-assigned this Nov 1, 2022
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Nov 2, 2022
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Nov 2, 2022
cdce8p added a commit to pylint-dev/astroid that referenced this issue Nov 3, 2022
Prevent returning an empty list for `ClassDef.slots()` when the mro list contains one class & it is not `object`. Refs pylint-dev/pylint#5099

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@cdce8p cdce8p added Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Nov 4, 2022
@cdce8p cdce8p added this to the 2.15.6 milestone Nov 4, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.6, 2.15.7 Nov 14, 2022
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Nov 19, 2022
Prevent returning an empty list for `ClassDef.slots()` when the mro list contains one class & it is not `object`. Refs pylint-dev/pylint#5099

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Nov 19, 2022
Prevent returning an empty list for `ClassDef.slots()` when the mro list contains one class & it is not `object`. Refs pylint-dev/pylint#5099

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@Pierre-Sassoulas
Copy link
Member

This might be fixed if you upgrade astroid or on a new install, because we released astroid 2.12.13 with pylint-dev/astroid#1861 and pylint can use the latest astroid. Keeping in 2.15.7, do you think we need a regression tests @mbyrnepr2 ?

@mbyrnepr2
Copy link
Member

I'm thinking no @Pierre-Sassoulas because of the test in astroid & based on the conversation around duplicating tests in Pylint which are already in astroid.
But let me know & I'm happy to add a test here if there are some doubts with the testing 🧪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

No branches or pull requests

4 participants