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

Fixes issus #13382 #13390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fixes issus #13382 #13390

wants to merge 1 commit into from

Conversation

InFiNiTy0639
Copy link

Fixing Type Annotation for lock in Handler class

The type annotation for the lock attribute in the Handler class was previously incorrectly defined as threading.Lock | None in the typeshed stub. This is inconsistent with the CPython implementation, which uses threading.RLock (a reentrant lock) instead of a simple lock.

Changes made:

  • Updated the type annotation for the lock attribute in the Handler class from threading.Lock | None to threading.RLock | None.
  • This change aligns the typeshed stub with the actual implementation in CPython, where RLock is used instead of Lock.

Reasoning:

  • The CPython source code (from version 2.5 onward) uses threading.RLock instead of threading.Lock for the lock attribute in the Handler class.
  • RLock is not a subclass of Lock, so using Lock in the typeshed definition was incorrect.
  • This update ensures the correct typing is reflected and avoids confusion when using static analysis tools or type checkers.

Copy link
Contributor

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

@@ -246,7 +246,7 @@ NOTSET: Final = 0
class Handler(Filterer):
level: int # undocumented
formatter: Formatter | None # undocumented
lock: threading.Lock | None # undocumented
lock: threading.RLock | None # Corrected type
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the comment needs to be changed.

Copy link
Author

Choose a reason for hiding this comment

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

Ok 👍🙂

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.

2 participants