pycharm bug? Inspection false positives when import an asynccontextmanager

414 Views Asked by At

EDIT now a reproduced issue https://youtrack.jetbrains.com/issue/PY-65385

EDIT i made a more minimal reproduction, and discovered it only happens when importing..

As of today Pycharm is highlighting calls to an asynccontextmanager as missing non-existent param "_P", but only if import the manager from another module.

There are no runtime errors - just pycharm highlighting and complaining

a.py

@asynccontextmanager
async def cont_manager():
    try:
        ...
        yield
    finally:
        ...


async def get_man():
    async with cont_manager() as con_man:
        ...

works fine, no highlighting or inspection errors.

but

a.py

from b import cont_manager

async def get_man():
    async with cont_manager() as con_man:
        ...

b.py
from contextlib import asynccontextmanager

@asynccontextmanager
async def cont_manager():
    try:
        ...
        yield
    finally:
        ...

Pycharm highlights closing paren of async with cont_manager() and says "Parameter '_P' unfilled"

a context manager that does require params gets the same inspection error:

a.py
from b import cont_man_params

async with cont_man_params(param1='pppprrrrr1') as con_man_params:
    ...


b.py
@asynccontextmanager
async def cont_man_params(param1, param2):
    print(param1, param2)
    try:
        yield
    finally:
        ...

i get unexpected argument for param1='...', unfulfilled param '_P' and no mention of missing param2

i tried invalidating all caches etc, delete .idea, reverted to known good revision, created a new project to make minimal examples, tried 3.11 and 3.12 and issue persists...

**** original message:

i'm relatively green, but i think this is the ide not me?

i'm on PyCharm 2023.3.1 (Professional Edition), i have AIAssistant, not that that should be relevant, but when weird shit happens i tend to look at new tech in the stack.... i've updated pycharm and all plugins, invalidated all caches and restarted, checked out known good revisions of the repo, and in any case my tests all still pass - it's just the ide that's freaking out.

yesterday everything was fine, today i opened pycharm, made no changes, and in loads of places ide is complaining that either parmas are unfilled, or they are unexpected.

eg here in test_reddit_cm() ide says call to async with reddit_cm() as reddit: suffers Parameter '_P unfulfilled in reddit_cm()

i have never heard of "_P", i searched the codebase, and apart from it being included in other strings eg "EPISODE_PAGE_TITLE" it is not a param. and even if it was, it clearly is not in the async def of reddit_cm()

there are other issues too, like funcs which do require params throwing ide complaints that the param is unexpected.

asynccontextmanager from asyncpraw.reddit import Reddit, Subreddit
from data.consts import GURU_SUB, REDDIT_CLIENT_ID, REDDIT_CLIENT_SEC,
\
    REDDIT_REF_TOK, REDIRECT, TEST_SUB, TEST_WIKI, USER_AGENT



@asynccontextmanager async def reddit_cm() -> Reddit:
    try:

        async with Reddit(
                client_id=REDDIT_CLIENT_ID,
                client_secret=REDDIT_CLIENT_SEC,
                user_agent=USER_AGENT,
                redirect_uri=REDIRECT,
                refresh_token=REDDIT_REF_TOK
        ) as reddit:
            yield reddit
    finally:
        await reddit.close()

... import pytest from asyncpraw.models import WikiPage from
asyncpraw.reddit import Reddit, Subreddit

from data.consts import EPISODES_WIKI, GURU_SUB, TEST_SUB, TEST_WIKI
from gurupod.redditbot.managers import reddit_cm, \
    subreddit_cm, wiki_page_cm from gurupod.redditbot.monitor import flair_submission_write_optional, run_jobs from
gurupod.redditbot.subred import submission_in_stream_by_id from
gurupod.redditbot.wrrite_to_web import edit_reddit_wiki,
submit_episode_subreddit from gurupod.writer import RWikiWriter


@pytest.mark.asyncio async def test_reddit_cm():
    async with reddit_cm() as reddit:
        assert isinstance(reddit, Reddit)

it's not really a functional issue, except if i start ignoring the highlights i'm going to miss real bugs

0

There are 0 best solutions below