-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
mypy: add --disallow-incomplete-defs option #2616
base: master
Are you sure you want to change the base?
mypy: add --disallow-incomplete-defs option #2616
Conversation
b71b791
to
ed8f641
Compare
I rebased that over master and it passes the 3.13 mypy check as well! |
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.
It's a constant battle to keep the docs clean, with only the type annotations or hints in the :param:
declarations, but not both.
While you go through and look for those (I didn't annotate every one, especially since many are outside where GH will allow line notes), also double check that merging #2285 didn't introduce any new wrinkles for this mypy option? 🙏
I fixed the functions I touched, and then fixed some for good measure!
That would require a rebase first, so you tell me if it's OK and I'll do. |
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.
Lots of good stuff in here, but I do have a few questions (the same one in multiple places, actually) about the choice of type annotation syntax. Overall very impressed with how thorough you were with cleaning up the docstrings!
double check that merging #2285 didn't introduce any new wrinkles for this mypy option? 🙏
That would require a rebase first, so you tell me if it's OK and I'll do.
Now that I think about it, your fixups were tested against the latest master
, including the merged changes from #2285. It passed, so you can just squash out the fixups after we settle the syntax question.
bc7b2b5
to
dcb9467
Compare
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.
Cleaned history all good.
I'll have to check other open PRs against this after merging, or make them re-run CI somehow. That's a future-me problem, for later in the week. 😁
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.
Had some remarks, but if the type checker is happy then so am I!
@@ -1030,12 +1034,11 @@ def error( | |||
self, | |||
trigger: Optional[Trigger] = None, | |||
exception: Optional[BaseException] = None, | |||
): | |||
) -> None: | |||
"""Called internally when a plugin causes an error. | |||
|
|||
:param trigger: the ``Trigger``\\ing line (if available) |
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.
Nit: could probably drop the reference to the type here? I would probably also omit the word "line"
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.
Maybe this would work, but I wouldn't want to take too much context out of the docstring.
:param trigger: the ``Trigger``\\ing line (if available) | |
:param trigger: the ``Trigger`` that led to the error, if available |
@@ -199,3 +209,5 @@ def mass(bot, trigger): | |||
stupid_part = '{:.2f} oz'.format(ounce) | |||
|
|||
bot.say('{} = {}'.format(metric_part, stupid_part)) | |||
|
|||
return 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.
Same here: I probably would have left off the explicit return
@@ -13,21 +13,21 @@ | |||
import inspect | |||
import logging | |||
import traceback | |||
from typing import Callable, Optional | |||
from typing import Callable |
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.
Same here: Is there a reason to prefer the deprecated typing.Callable
over collections.abc.Callable
?
Callable, | ||
Optional, | ||
Sequence, |
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.
Any reason not to import these from collections.abc
since the typing
counterparts are deprecated since Python 3.9?
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.
The only reason would be "not touching more than necessary", I think.
Switching from the deprecated imports to their replacements is unrelated to the PR's goal of making --disallow-incomplete-defs
work.
@@ -26,6 +26,7 @@ | |||
import threading | |||
from typing import ( | |||
Any, | |||
Callable, |
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.
Same comment here about collections.abc
vs. typing
self, | ||
expression_str: str, | ||
timeout: float = 5.0, | ||
) -> int | float: |
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.
IIRC, int | float
is redundant because float
can annotate both per PEP 484
I'm okay with explicitly annotating it as a way to document the specific type that will be present but would personally prefer an alias for the union in that case, as a place to leave a comment about why we don't do it the "usual" way.
return super().__contains__(self._make_key(key)) | ||
|
||
def __setitem__(self, key: Optional[str], value): | ||
def __setitem__(self, key: str | None, value: Any) -> Any: |
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.
Nit: that can be None
def __setitem__(self, key: str | None, value: Any) -> Any: | |
def __setitem__(self, key: str | None, value: Any) -> None: |
Description
Tin, with the necessary type definition fix. Related to #2603 for Sopel 8.0.1.
Note: I used
Any
in several places, in particular insopel.tools.identifiers
. I'm not really happy about it. However, the best fix is to properly type annotate instances, i.e. doing something likeusers: dict[str, User] = SopelIdentifierMemory()
as it should properly type check theusers
sopel memory object.Checklist
make qa
(runsmake lint
andmake test
)