Skip to content

Type inference behaves differently dependening on usage of intermediate variables #5281

@Tomaz-Vieira

Description

@Tomaz-Vieira

Describe the bug
I get different behaviors of type inference depending on whether or not I use intermediate variables.

To Reproduce

from concurrent.futures import ThreadPoolExecutor
import asyncio
from typing_extensions import reveal_type

def do_work() -> int:
    return 123

async def foo():
    executor = ThreadPoolExecutor()
    result = await asyncio.wrap_future(executor.submit(do_work))
    reveal_type(result) # Type of "result" is "_T@wrap_future"

    #the same, but now with a variable holding the concurrent future
    concurrent_future = executor.submit(do_work)
    result2 = await asyncio.wrap_future(concurrent_future)
    reveal_type(result2) # Type of "result2" is "int"

Expected behavior
I expected the concurrent_future variable to not be necessary for result2 to be inferred as an int.

VS Code extension or command-line
Commnd line version 1.1.313

Additional Context
I just tested and this behavior started at 1.1.306

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions