PyCQA / redbaron

Bottom-up approach to refactoring in python
http://redbaron.pycqa.org/
694 stars 74 forks source link

[BUG] GroupingError #188

Open xiaoyao1949 opened 5 years ago

xiaoyao1949 commented 5 years ago

error here is my code:

async def request(
        self,
        method: Text = "post",
        subpath: Optional[Text] = None,
        content_type: Optional[Text] = "application/json",
        return_method: Text = "json",
        **kwargs: Any
    ):
        """Send a HTTP request to the endpoint.

        All additional arguments will get passed through
        to aiohttp's `session.request`."""

        # create the appropriate headers
        headers = {}
        if content_type:
            headers["Content-Type"] = content_type

        if "headers" in kwargs:
            headers.update(kwargs["headers"])
            del kwargs["headers"]

        url = concat_url(self.url, subpath)
        async with self.session() as session:
            async with session.request(
                method,
                url,
                headers=headers,
                params=self.combine_parameters(kwargs),
                **kwargs
            ) as resp:
                if resp.status >= 400:
                    raise ClientResponseError(
                        resp.status, resp.reason, await resp.content.read()
                    )
                return await getattr(resp, return_method)()
Jackenmen commented 4 years ago

I have the same problem with all objects that I await and pass to a function in same expression, e.g.

max(await x())

or

l = []
l.append(await y())

If I put parentheses around awaited object, it will work, so:

max(await (x()))

or

l = []
l.append(await (y()))

doesn't raise this error.

webknjaz commented 4 years ago

Looks like the grammar in baron is ready but a redbaron wrapper is missing: https://baron.readthedocs.io/en/latest/grammar.html#async-with

MoBoo commented 1 year ago

Problem still exists to this date. Is there any update on this?