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

Not showing top-level asynchronous function defintion with jedi.api.names #1309

Closed
CXuesong opened this issue Apr 7, 2019 · 4 comments
Closed
Labels

Comments

@CXuesong
Copy link
Contributor

CXuesong commented Apr 7, 2019

I tried to use jedi.api.names to generate document outline for the following code

# AsyncFunctions.py
import asyncio

def func() -> int:
    asyncio.run(func_async(0))

async def func_async(arg) -> int:
    await asyncio.sleep(1000)
    return 100

with the following code (flattened document outline)

import io
import jedi

with io.open("AsyncFunctions.py", "r") as f:
    content = f.read()
    for n in jedi.api.names(content, f.name, all_scopes=True):
        print(n, n.parent(), n.is_definition())

It gives me the following output

<Definition module asyncio> <Definition module AsyncFunctions> True
<Definition def func> <Definition module AsyncFunctions> True
<Definition def func_async> <Definition module AsyncFunctions> True
<Definition param arg> <Definition def func_async> True

The result here is satisfactory.

However, if I remove all_scopes=True (use False by default), the output becomes

<Definition module asyncio> <Definition module AsyncFunctions> True
<Definition def func> <Definition module AsyncFunctions> True

The problem here, is func_async, regardless of it being a top-level function, is missing. Is this a bug or by design?

@davidhalter davidhalter added the bug label Apr 7, 2019
@davidhalter
Copy link
Owner

davidhalter commented Apr 7, 2019

It's probably a bug :)

I also think that it's probably an easy fix.

@CXuesong
Copy link
Contributor Author

CXuesong commented Apr 8, 2019

Okay. It seems that I need to make some modifications to get_module_names, because async functions are actually functions wrapped in async_stmt.

I also noted there are still top-level function parameters and in-function local variables included in the result even if all_scopes=False, i.e. #1202, and curious about the current situation of that issue and PR #1203 . May I try to fix this as well?

@davidhalter
Copy link
Owner

I just merged #1203, so feel free to work on it :)

@davidhalter
Copy link
Owner

#1313 was merged and should solve this issue, thanks for helping out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants