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

name-error when using async with #978

Closed
dpcollins-google opened this issue Aug 16, 2021 · 2 comments
Closed

name-error when using async with #978

dpcollins-google opened this issue Aug 16, 2021 · 2 comments
Assignees
Labels
bug cat: generics Generic, TypeVar, containers

Comments

@dpcollins-google
Copy link

The following code:

async with (await conn_fut) as connection:
                        # Needs to happen prior to reinitialization to clear outstanding waiters.
                        if last_failure is not None:
                            while not self._write_queue.empty():
                                self._write_queue.get_nowait().response_future.set_exception(
                                    last_failure
                                )
                        self._read_queue = asyncio.Queue(maxsize=1)
                        self._write_queue = asyncio.Queue(maxsize=1)
                        await self._reinitializer.reinitialize(connection, last_failure)
                        self._initialized_once.set()
                        bad_retries = 0
                        await self._loop_connection(connection)

Triggers:

File ".../google/cloud/pubsublite/internal/wire/retrying_connection.py", line 97, in _run_loop: Name 'connection' is not defined [name-error]
File ".../google/cloud/pubsublite/internal/wire/retrying_connection.py", line 100, in _run_loop: Name 'connection' is not defined [name-error]
@rchen152
Copy link
Contributor

Here's a self-contained example of the issue:

# connection.pyi
import abc
from typing import Any, AsyncContextManager, Coroutine

class Connection(AsyncContextManager): ...

class ConnectionFactory(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def new(self) -> Coroutine[Any, Any, Connection]: ...

# retrying_connection.py
from typing import Any
from connection import ConnectionFactory

class RetryingConnection:

    _connection_factory: ConnectionFactory
    _reinitializer: Any

    async def _run_loop(self):
        conn_fut = self._connection_factory.new()
        async with (await conn_fut) as connection:
          await connection

Running pytype-single retrying_connection.py produces:

File "retrying_connection.py", line 12, in _run_loop: Name 'connection' is not defined [name-error]

@rchen152
Copy link
Contributor

When I run with -v4, I see this suspicious debug output:

INFO:pytype.vm  >  ## 11: 12: YIELD_FROM 
[...]
INFO:pytype.vm  >  ## 11: 13: SETUP_ASYNC_WITH  30
[...]
INFO:pytype.vm  >  ## 11: 14: STORE_FAST  connection
--> DEBUG:pytype.attribute Setting connection to the 0 values in <Variable v604: 0 choices> <-- ZERO CHOICES?
[...]
INFO:pytype.vm  >  ## 12: 15: LOAD_FAST  connection
INFO:pytype.errors Added error to log: name-error

@rchen152 rchen152 self-assigned this Aug 18, 2021
@rchen152 rchen152 added the cat: generics Generic, TypeVar, containers label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: generics Generic, TypeVar, containers
Projects
None yet
Development

No branches or pull requests

2 participants