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

Decorator seems not to be applied to a function under some circumstances (inferred return type, recursive reference, loop, generator) #9492

Closed
Azureblade3808 opened this issue Nov 22, 2024 · 1 comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@Azureblade3808
Copy link
Contributor

Describe the bug

I am not able to describe it clearly. See sample code below.

Code or Screenshots

from __future__ import annotations

from contextlib import contextmanager

@contextmanager
# The following function is having an omitted return type.
# If the return type is declared explicitly (even as `-> Any`), this issue goes away.
def f():
    yield

    # Must be inside a loop. `for` or `while` doesn't matter.
    for _ in ():
        # The following `f()` is regarded as if it's having its original signature and 
        # returns a `Generator` instead of a context manager, so the `with` clause gets
        # reported.
        with f():
            return

VS Code extension or command-line

Pyright 1.1.389.

@Azureblade3808 Azureblade3808 added the bug Something isn't working label Nov 22, 2024
erictraut added a commit that referenced this issue Nov 29, 2024
…ed and has no explicit return type annotation and the body references the decorated function in a loop. This addresses #9492.
erictraut added a commit that referenced this issue Nov 29, 2024
…ed and has no explicit return type annotation and the body references the decorated function in a loop. This addresses #9492. (#9518)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Nov 29, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.390.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants