GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `asyncio.staggered` is missing `typing` import · Issue #119121 · python/cpython

asyncio.staggered is missing typing import #119121

New issue
Copy link
New issue
Copy link
Closed
Closed
asyncio.staggered is missing typing import#119121
Copy link
Assignees
sobolevn
Labels
topic-asynciotopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@mgorny
mgorny
opened on May 17, 2024
Issue body actions

Bug report

Bug description:

asyncio/staggered.py is using typing.Optional:

cpython/Lib/asyncio/staggered.py

Line 73 in 65de194

previous_failed: typing.Optional[locks.Event]) -> None:

However, #114281 removed the typing import. This causes test failures in aiohappyeyeballs:

coro_fns = <generator object start_connection.<locals>.<genexpr> at 0x7feba06d1be0>, delay = 0.3

    async def staggered_race(coro_fns, delay, *, loop=None):
        """Run coroutines with staggered start times and take the first to finish.
    
        This method takes an iterable of coroutine functions. The first one is
        started immediately. From then on, whenever the immediately preceding one
        fails (raises an exception), or when *delay* seconds has passed, the next
        coroutine is started. This continues until one of the coroutines complete
        successfully, in which case all others are cancelled, or until all
        coroutines fail.
    
        The coroutines provided should be well-behaved in the following way:
    
        * They should only ``return`` if completed successfully.
    
        * They should always raise an exception if they did not complete
          successfully. In particular, if they handle cancellation, they should
          probably reraise, like this::
    
            try:
                # do work
            except asyncio.CancelledError:
                # undo partially completed work
                raise
    
        Args:
            coro_fns: an iterable of coroutine functions, i.e. callables that
                return a coroutine object when called. Use ``functools.partial`` or
                lambdas to pass arguments.
    
            delay: amount of time, in seconds, between starting coroutines. If
                ``None``, the coroutines will run sequentially.
    
            loop: the event loop to use.
    
        Returns:
            tuple *(winner_result, winner_index, exceptions)* where
    
            - *winner_result*: the result of the winning coroutine, or ``None``
              if no coroutines won.
    
            - *winner_index*: the index of the winning coroutine in
              ``coro_fns``, or ``None`` if no coroutines won. If the winning
              coroutine may return None on success, *winner_index* can be used
              to definitively determine whether any coroutine won.
    
            - *exceptions*: list of exceptions returned by the coroutines.
              ``len(exceptions)`` is equal to the number of coroutines actually
              started, and the order is the same as in ``coro_fns``. The winning
              coroutine's entry is ``None``.
    
        """
        # TODO: when we have aiter() and anext(), allow async iterables in coro_fns.
        loop = loop or events.get_running_loop()
        enum_coro_fns = enumerate(coro_fns)
        winner_result = None
        winner_index = None
        exceptions = []
        running_tasks = []
    
        async def run_one_coro(
>               previous_failed: typing.Optional[locks.Event]) -> None:
E               NameError: name 'typing' is not defined. Did you forget to import 'typing'?

coro_fns   = <generator object start_connection.<locals>.<genexpr> at 0x7feba06d1be0>
delay      = 0.3
enum_coro_fns = <enumerate object at 0x7feba06223e0>
exceptions = []
loop       = <_UnixSelectorEventLoop running=False closed=False debug=False>
running_tasks = []
winner_index = None
winner_result = None

/usr/lib/python3.13/asyncio/staggered.py:73: NameError

CC @AA-Turner

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-119121: Fix and test async.staggered.staggered_race #119173
  • [3.13] gh-119121: Fix and test async.staggered.staggered_race (GH-119173) #119206

Activity

  1. mgorny
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 17, 2024
  2. Eclips4 commented on May 17, 2024

    @Eclips4
    Eclips4
    on May 17, 2024
    Member
    More actions

    cc @sobolevn as well

  3. Eclips4
    added
    topic-asyncio
    topic-typing
    on May 17, 2024
  4. github-project-automation
    added this to asyncioon May 17, 2024
  5. github-project-automation
    moved this to Todo in asyncioon May 17, 2024
  6. JelleZijlstra commented on May 17, 2024

    @JelleZijlstra
    JelleZijlstra
    on May 17, 2024
    Member
    More actions

    This is easy to fix but the weird thing is that no unit tests caught this; the NameError happens on any call to staggered_race(). We should really have test coverage for staggered.py.

    Linking #114282 where this was changed.

    Reacted by Shantanu
  7. sobolevn
    self-assigned this
    on May 17, 2024
  8. sobolevn commented on May 17, 2024

    @sobolevn
    sobolevn
    on May 17, 2024
    Member
    More actions

    I'll fix it, sorry!

    Reacted by Alex Waygood, Michał Górny, Kirill Podoprigora and Jelle Zijlstra
  9. sobolevn
    added 2 commits that reference this issue on May 19, 2024

    pythongh-119121: Fix and test `async.staggered.staggered_race`

    8d36cd5

    gh-119121: Fix and test `async.staggered.staggered_race` (#119173)

    16b46eb
  10. miss-islington
    added a commit that references this issue on May 20, 2024

    pythongh-119121: Fix and test `async.staggered.staggered_race` (pytho…

    195011d
  11. sobolevn
    added a commit that references this issue on May 20, 2024

    [3.13] gh-119121: Fix and test `async.staggered.staggered_race` (GH-1…

    3a8ab99
  12. sobolevn
    closed this as completedon May 20, 2024
  13. github-project-automation
    moved this from Todo to Done in asyncioon May 20, 2024
  14. mgorny commented on May 20, 2024

    @mgorny
    mgorny
    on May 20, 2024
    ContributorAuthor
    More actions

    Thanks a lot! I can confirm that aiohappyeyeballs are good now.

  15. Kronuz
    added a commit that references this issue on May 20, 2024

    [3.13] pythongh-119121: Fix and test `async.staggered.staggered_race` (…

    dcf3f18
  16. estyxx
    added a commit that references this issue on Jul 17, 2024

    pythongh-119121: Fix and test `async.staggered.staggered_race` (pytho…

    a3bb42d
  17. Bluscream commented on Sep 1, 2024

    @Bluscream
    Bluscream
    on Sep 1, 2024
    More actions

    Yoo i actually had to fix this now aswell :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sobolevn
    sobolevn

Labels

topic-asynciotopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • asyncio
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.