KomodoEdit icon indicating copy to clipboard operation
KomodoEdit copied to clipboard

Codeintel on KomodoIDE11 fails when using python3 `async with`

Open Callek opened this issue 7 years ago • 7 comments

Short Summary

When using async with on python3 code, CodeIntel fails

Steps to Reproduce

#!/usr/bin/env python
"""Generic utils for scriptworker.

Attributes:
    log (logging.Logger): the log object for the module

"""

import logging

log = logging.getLogger(__name__)

async def download_file(context, url, abs_filename, session=None, chunk_size=128):
    """Download a file, async.

    Args:
        context (scriptworker.context.Context): the scriptworker context.
        url (str): the url to download
        abs_filename (str): the path to download to
        session (aiohttp.ClientSession, optional): the session to use.  If
            None, use context.session.  Defaults to None.
        chunk_size (int, optional): the chunk size to read from the response
            at a time.  Default is 128.

    """
    session = session or context.session
    log.info("Downloading %s", url)
    async with session.get(url) as resp:
        if resp.status != 200:
            raise Exception("{} status {} is not 200!".format(url, resp.status))
        with open(abs_filename, 'wb') as fd:
            while True:
                chunk = await resp.content.read(chunk_size)
                if not chunk:
                    break
                fd.write(chunk)
    log.info("Done")

Expected results

CodeIntel to show me symbols

Actual results

No Symbols found.

Platform Information

Komodo Edit or IDE? IDE Komodo Version? 11.0.2 Operating System (and version)? Ubuntu 16.04.3 LTS

Additional Information

No relevant errors in any logs (with default log verbosity, if I can provide actual debug spewing logs I'm happy to)

Callek avatar Jan 29 '18 15:01 Callek

Also locally $ python3 --version Python 3.5.2

Callek avatar Jan 29 '18 15:01 Callek

Hi, thanks for the report.

mitchell-as avatar Jan 29 '18 15:01 mitchell-as

Note to self: remove the async and await keywords, and codeintel works properly. It appears the parsers do not account for those keywords yet.

mitchell-as avatar Jan 29 '18 15:01 mitchell-as

@mitchell-as locally using async def ... and await foo() in local files seems to get python3 (new codeintel not legacy) to work fine in getting symbols, minimally reducing to async with where if I removed async it worked fine.

Callek avatar Jan 29 '18 16:01 Callek

Related but possibly an issue in itself, I am running Python 3.7 on the affected machine and in this file ..\dbgp\python3lib\dbgp\client.py

the dbgp server/client blows up when it hits functions like def cmdloop(self, async=0) @ l2523 with a syntax error. I went in and changed all of the identifiers async to _async and didn't have any problems. I believe dbgp's protocol has commands with the word async so a find&replace would break the code if changed blindly.

devdave avatar Sep 01 '18 03:09 devdave

@cgchoffman I think this might be the same as https://github.com/Komodo/KomodoEdit/issues/3592

Naatan avatar Sep 04 '18 18:09 Naatan

Hi! Still having the same issue running Komodo IDE, version 12.0.1, build 91869, platform linux-x86_64, built on Mon Feb 10 19:37:24 2020 on Ubuntu 20.04 and Python 3.8.2 The code snippet from https://docs.aiohttp.org/en/stable/client_reference.html can be used for reproducing inappropriate behaviour:

import aiohttp
import asyncio
async def fetch(client):
    async with client.get('http://python.org') as resp:
        assert resp.status == 200
        return await resp.text()

async def main():
    async with aiohttp.ClientSession() as client:
        html = await fetch(client)
        print(html)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

leon-id avatar Aug 10 '20 18:08 leon-id