Skip to content

most asyncio lock methods always return True#7122

Merged
Akuli merged 1 commit into
python:masterfrom
graingert:patch-2
Feb 4, 2022
Merged

most asyncio lock methods always return True#7122
Akuli merged 1 commit into
python:masterfrom
graingert:patch-2

Conversation

@graingert
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Copy Markdown
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, although I don't understand why always returning True would be a good idea.

@aiudirog
Copy link
Copy Markdown

@Akuli I just came across this ticket trying to trace why mypy is suddenly failing a custom asyncio Semaphore implementation I have.

While I get where @graingert is coming from, those methods returned bool before for compatibility/consistency with their threading counterparts where False is returned if the lock isn't acquired within a timeout or is non-blocking and can't be immediately acquired.

Asyncio has neither of these features built-in, instead preferring to let the user wrap it up in something like asyncio.wait_for(), so while it doesn't need to return anything, it always returns True for consistency.

This change isn't really a problem, as I can just update my code, but I figured I'd drop the context for anyone else trying to figure out what happened.


Putting the exact mypy error here for search engine indexing:

error: Return type "Coroutine[Any, Any, bool]" of "acquire" incompatibile with return type "Courinte[Any, Any, Literal[True]]" in supertype "Semaphore" [override]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants