Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Remove unneeded loop arguments #1006

Merged

Conversation

bmerry
Copy link
Collaborator

@bmerry bmerry commented Jun 9, 2021

What do these changes do?

The new 2.0 implementation has a number of places where it either takes an explicit loop parameter, or passes one to an asyncio function. The need for this was largely removed in Python 3.5.3 (because get_event_loop was changed to return the event loop of the current task when called from inside a task), and many functions (such as wait_for deprecated the parameter in 3.8 with removal for 3.10. Other functions (like open_connection) didn't deprecate it, but made it optional and documented that it is not needed when called from a coroutine. I wouldn't be surprised if they are deprecated in future.

Are there changes in behavior for the user?

Only compared to 2.0.0a1:

  1. __del__ will now always use asyncio.get_event_loop(). But __del__ is broken anyway, for reasons I've explained in Migration to aioredis 2.0 #930.

  2. PubSub.run_in_thread is a synchronous function but needs to know the event loop to run. I've updated it to take an explicit loop argument. This makes it possible to construct the Redis object before the event loop. I'm going to file a separate issue to remove this function anyway, since aioredis should provide concurrency via asyncio tasks rather than threads, and the one test function has been disabled because it is broken.

Related issue number

#1002

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example:
      Fix issue with non-ascii contents in doctest text files.

This makes aioredis more consistent with other libraries that have
removed the need to explicitly specify the loop to use. This has two
knock-on effects:

1. __del__ will now always use asyncio.get_event_loop(). But `__del__`
is broken anyway, for reasons I've explained in aio-libs-abandoned#930.

2. PubSub.run_in_thread is a synchronous function but needs to know the
event loop to run. I've updated it to take an explicit loop argument.
This makes it possible to construct the Redis object before the event
loop. I'm going to file a separate issue to remove this function anyway,
since aioredis should provide concurrency via asyncio tasks rather than
threads, and the one test function has been disabled because it is
broken.

Closes aio-libs-abandoned#1002.
@bmerry
Copy link
Collaborator Author

bmerry commented Jun 9, 2021

I'm not sure what to do with regards to testing around PubSub.run_in_thread. redis-py has very minimal testing of this function (just one test for a particular feature), and @seandstewart disabled it in #891 with a comment that it was broken and made the tests hang.

@codecov
Copy link

codecov bot commented Jun 9, 2021

Codecov Report

Merging #1006 (3974143) into master (f12a6dc) will decrease coverage by 0.00%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1006      +/-   ##
==========================================
- Coverage   88.62%   88.61%   -0.01%     
==========================================
  Files          21       21              
  Lines        6784     6781       -3     
  Branches      653      653              
==========================================
- Hits         6012     6009       -3     
  Misses        610      610              
  Partials      162      162              
Flag Coverage Δ
unit 88.58% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aioredis/client.py 81.09% <0.00%> (ø)
aioredis/connection.py 65.52% <100.00%> (-0.13%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f12a6dc...3974143. Read the comment docs.

@seandstewart
Copy link
Collaborator

Thanks for the work here - it was on my docket to get rid of these so I'm glad it's getting done!

@seandstewart seandstewart merged commit 6c0bf2b into aio-libs-abandoned:master Jun 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants