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

False positive not-async-context-manager with Pydantic PrivateAttr #9813

Open
jamesbraza opened this issue Jul 19, 2024 · 0 comments
Open

False positive not-async-context-manager with Pydantic PrivateAttr #9813

jamesbraza opened this issue Jul 19, 2024 · 0 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable

Comments

@jamesbraza
Copy link

jamesbraza commented Jul 19, 2024

Bug description

There is a false positive not-async-context-manager when using Pydantic v2's PrivateAttr. Fyi I am coming from pydantic/pydantic#9921

import asyncio

from pydantic import BaseModel, PrivateAttr


class SomeModel(BaseModel):
    _some_lock: asyncio.Lock = PrivateAttr(default_factory=asyncio.Lock)

    async def some_method(self) -> None:
        async with self._some_lock:
            await asyncio.sleep(1)


model = SomeModel()
asyncio.run(model.some_method())

Configuration

load-plugins = "pylint_pydantic"

Command used

pylint a.py

Pylint output

a.py:10:8: E1701: Async context manager 'ModelPrivateAttr' doesn't implement __aenter__ and __aexit__. (not-async-context-manager)

Expected behavior

No message

Pylint version

pylint 3.2.5
astroid 3.2.3
Python 3.12.4 (main, Jul  3 2024, 13:35:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]

OS / Environment

macOS Sonoma version 14.3

Additional dependencies

pydantic version: 2.8.2
        pydantic-core version: 2.20.1
          pydantic-core build: profile=release pgo=true
                 install path: /path/to/venv/lib/python3.12/site-packages/pydantic
               python version: 3.12.4 (main, Jul  3 2024, 13:35:11) [Clang 15.0.0 (clang-1500.1.0.2.5)]
                     platform: macOS-14.3-arm64-arm-64bit
             related packages: mypy-1.10.1 typing_extensions-4.12.2 fastapi-0.111.1
                       commit: unknown
@jamesbraza jamesbraza added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 19, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable Lib specific 💅 This affect the code from a particular library and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

No branches or pull requests

2 participants