-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Update and provide fixes for mypy pre-commit #12389
Conversation
bbd8ba8
to
ac2c42c
Compare
@@ -941,7 +945,7 @@ def html_index_with_onetime_server( | |||
""" | |||
|
|||
class InDirectoryServer(http.server.ThreadingHTTPServer): | |||
def finish_request(self, request: Any, client_address: Any) -> None: | |||
def finish_request(self: "Self", request: Any, client_address: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Mypy requires this change I don’t understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it the call below it:
self.RequestHandlerClass(
request,
client_address,
self,
directory=str(html_index_for_packages), # type: ignore[call-arg]
)
Causes the mypy error:
tests/conftest.py:952: error: Argument 3 has incompatible type
"InDirectoryServer"; expected "Self" [arg-type]
self,
^~~~
I did not investigate why mypy now requires self
in this case to be type hinted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I kind of understand the reason Mypy needs it, but it really shouldn’t need it. It could be a bug.
Merging this on the basis of the approvals here. |
* Update mypy to 1.6.1 * Fix mypy "Source file found twice under different module names" error * Ignore type of intialized abstract class in tests * Use more specific type ignore method-assign * Type ignore for message.get_all * Remove unused type ignore * Add SizedBuffer type for xmlrpc.client.Transport subclass * Add Self type for RequestHandlerClass in test * Add type ignore for shutil.rmtree onexc handler * Quote SizedBuffer * Add news entry * Remove no longer correct comment * Update self import * Also ignore type onerror=handler * Update news entry * Update news entry
Update and provide fixes for mypy pre-commit
When running pre-commit locally with Python 3.12 on Pip main I am getting the error:
I assume this is because the version of MyPy in the pre-commit is quite old. I updated it and then went through all the new errors it produced trying to fix them as seemed most appropriate.
I ended up having to add a type-ignore on this line regardless as although it now recognizes onexc it can not translate the type: