All jobs

Fix "TypeError: As of 3.10, the *loop* parameter was removed from Lock()" in asyncio

Yes. An agent finds every loop= argument passed to an asyncio primitive, removes it or the dead code around it, and tests on Python 3.9 through 3.12.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

Until Python 3.10, asyncio.Lock, Event, Queue, Semaphore, sleep, gather and wait_for accepted a loop argument. It was deprecated in 3.8 and removed in 3.10, and libraries that passed it now fail at the call. SharpBit/brawlstats, an API wrapper with a sync and an async client, is a good example because nothing in the project warns about it. setup.py declares python_requires='>=3.9.0', tox.ini lists py39 to py312, the workflow in .github/workflows/tests.yml runs all four, and line 63 of brawlstats/core.py still reads self.lock = asyncio.Lock(loop=self.loop).

The agent reproduces it with a short script, because the existing tests in tests/test_async.py need a real API TOKEN and never take this path. Line 63 only runs when the client is built with is_async=True and prevent_ratelimit=True. With both set, Python 3.9 prints DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10, Python 3.10 raises the error in the title, and 3.11 and 3.12 raise a differently worded one, Lock.__init__() got an unexpected keyword argument 'loop'. Searching for the 3.10 wording alone would miss reports from newer interpreters, so the agent records all three.

Before deleting loop=self.loop, it reads what the lock is for. A search for self.lock and prevent_ratelimit across the package returns only lines 61 to 63: the lock is created and never acquired. CHANGELOG.md explains it, since the 4.2.0 entry lists "Removed the prevent_ratelimit option for the Client" and the class docstring no longer documents the option. The correct change is therefore to delete the three leftover lines, not to repair a constructor call for an object nothing uses. In a project where the lock is used, the fix is the bare asyncio.Lock(), which binds to the running loop on first use.

It finishes by checking the other loop handling in the same constructor and separating what is broken from what merely warns. Line 50, options.get('loop', asyncio.get_event_loop()), calls get_event_loop() even when the caller supplied a loop, and on Python 3.12 that prints DeprecationWarning: There is no current event loop when the client is created outside a coroutine. Line 58 passes loop= to aiohttp.ClientSession, which is aiohttp's own parameter and still accepted. The agent adds a test that constructs the async client against an unreachable base_url, with and without the old option, on each interpreter in tox.ini, and lists the line 50 warning as a follow-up.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This project fails on Python 3.10 or later with \"TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary\", or on 3.11 and later with \"Lock.__init__() got an unexpected keyword argument 'loop'\". Find every place a loop argument is passed to an asyncio primitive or function: Lock, Event, Condition, Semaphore, BoundedSemaphore, Queue and its variants, sleep, wait, wait_for, gather, shield, as_completed, open_connection, start_server and subprocess helpers. For each one, read how the object is used afterwards. If it is never used, remove it and the option that creates it, and check the changelog and docs to confirm that matches what the project says it supports. If it is used, drop the loop argument and make sure the object is created or first used inside the running loop. Leave loop arguments that belong to third-party libraries alone unless that library rejects them, and say which ones you left. Write a test that reaches each changed line without real network access or credentials, and run it on every Python version the project's packaging metadata or CI lists. Report separately, without fixing, any call to asyncio.get_event_loop() made outside a running loop and the warning it prints on Python 3.12. Open a pull request with the output from each interpreter.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request with a deletion at its centre. For brawlstats it removes three lines from the constructor in core.py and adds a test file that builds the async client with and without the old option. The description quotes what each interpreter printed for the old code, one warning and two differently worded errors, and then the same script succeeding on all of them after the change.

The description spends more words on the decision than on the diff. It shows the search that found no reader of self.lock, cites the changelog entry that says the option was removed, and states the consequence for callers: prevent_ratelimit=True is now silently ignored instead of crashing, which is what the 4.2.0 notes already promised. If your project's lock is live, this section instead shows where it is acquired and confirms those call sites run inside the loop.

A follow-up list closes it: the eager get_event_loop() call with the warning text and line number, and the loop= passed to the HTTP session with a note that it is that library's argument. The reviewer checks that the new test fails when the three lines are restored, and decides whether the option should raise a clear error for callers who still pass it.

Run it on every issue labelled bug

Errors like this reach a library as issues from users on a newer Python than the maintainer runs. Add an automation on the repository's Project with the prompt above and a github trigger on issues.labeled, with labels set to the label you apply after triage. When an owner, member or collaborator adds it, a run starts and the issue is added after the prompt as event text, so the reporter's traceback and Python version reach the agent as data. The saved prompt stays the only instruction.

Because the prompt names one error family, an issue about something else produces a short report and no pull request. Keep the automation's max runs per hour low for a public repository, so a wave of duplicate reports after an interpreter release starts a handful of runs and holds or refuses the rest.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

This bug hides from the project's own checks. The CI matrix here already includes Python 3.12 and cannot catch it, because the failing branch needs an option the tests never pass and the tests need a secret a fork does not have. Finding it means building the object by hand on several interpreters and reading what each prints. The agent does that in a sandbox where four Python versions can be installed side by side, and the session keeps every command and its output for the reviewer.

The judgment call, delete or repair, depends on reading the changelog and searching for readers of one attribute. That is cheap work that a hurried fix skips, and skipping it leaves a lock that is constructed correctly and still does nothing. A run that returns the search results with the diff lets the reviewer check the decision against the evidence instead of repeating the investigation.

Frequently asked questions

Why is the error message different on Python 3.11 and 3.12?

Python 3.10 kept a check that recognised the old argument and raised the explanatory message. Later versions dropped that check, so the same call fails with the generic got an unexpected keyword argument 'loop'. Both mean the same thing and have the same fix.

Is it safe to just delete loop= everywhere?

For asyncio's own primitives, yes, provided the object is first used inside the loop that should own it. The primitive binds to the running loop at that point. Code that creates a lock in one thread's loop and awaits it in another was already wrong and now fails with a clearer error.

What about loop= passed to aiohttp or another library?

That is the library's parameter, not asyncio's, and each library retired it on its own schedule. The agent leaves those calls unless the installed version rejects them, and lists them so you can decide. Changing them belongs with a dependency upgrade.

Do I still need asyncio.get_event_loop()?

Inside a coroutine, asyncio.get_running_loop() is the direct replacement. At the top level, asyncio.run() creates and closes the loop for you. Calling get_event_loop() with no loop running prints a deprecation warning on Python 3.12, which is why the agent reports those calls even though they are not today's failure.

More asyncio jobs

More jobs like this: Fix a bug from an alert

Keep reading