Skip to content

function untyped after decorator transformation #19589

@grayjk

Description

@grayjk

Bug Report

To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&flags=disallow-any-decorated&gist=876af123e45fe566785e35c9e0b22821

import contextlib

exit_stack = contextlib.ExitStack()

def enter_context() -> None:
    if c:
        @exit_stack.callback
        def func1() -> None:
            pass
        
c = [1]
enter_context()

When c is a list, func1 is untyped after decoration

When c is a bool or int, func1 is typed after decoration

When c is a list defined before enter_context, func1 is a typed after decoration

Expected Behavior
func1 is typed after decoration

Actual Behavior
func1 is untyped after decoration

Your Environment

  • Mypy version used: 1.17.0
  • Mypy command-line flags: disallow-any-decorated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-disallow-anyThe disallow-any-* family of flags

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions