Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Invalid type inference in a conditional context manager with contextlib.nullcontext(). #16264

@francis-clairicia

Description

@francis-clairicia

Bug Report

When a ternary is used in a with or an async with statement to determine the final context manager, mypy cannot infer the expression type.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=a2db21d63361bc0f1f334ff337509fca

Expected Behavior

The expression should lead to TaskGroup type.

Actual Behavior

The expression lead to object type.

Your Environment

  • Mypy version used: 1.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions