-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Upgrade mypy to version 0.931 #12030
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Upgrade mypy to version 0.931. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| import signal | ||
| import sys | ||
| from types import FrameType, TracebackType | ||
| from typing import NoReturn, Type | ||
| from typing import NoReturn, Optional, Type | ||
|
|
||
|
|
||
| def daemonize_process(pid_file: str, logger: logging.Logger, chdir: str = "/") -> None: | ||
|
|
@@ -100,7 +100,9 @@ def daemonize_process(pid_file: str, logger: logging.Logger, chdir: str = "/") - | |
| # also catch any other uncaught exceptions before we get that far.) | ||
|
|
||
| def excepthook( | ||
| type_: Type[BaseException], value: BaseException, traceback: TracebackType | ||
| type_: Type[BaseException], | ||
| value: BaseException, | ||
| traceback: Optional[TracebackType], | ||
|
Comment on lines
+103
to
+105
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) -> None: | ||
| logger.critical("Unhanded exception", exc_info=(type_, value, traceback)) | ||
|
|
||
|
|
@@ -123,7 +125,7 @@ def excepthook( | |
| sys.exit(1) | ||
|
|
||
| # write a log line on SIGTERM. | ||
| def sigterm(signum: signal.Signals, frame: FrameType) -> NoReturn: | ||
| def sigterm(signum: int, frame: Optional[FrameType]) -> NoReturn: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| logger.warning("Caught signal %s. Stopping daemon." % signum) | ||
| sys.exit(0) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
|
|
||
| import functools | ||
| import sys | ||
| from typing import Any, Callable, Generator, List, TypeVar | ||
| from typing import Any, Callable, Generator, List, TypeVar, cast | ||
|
|
||
| from twisted.internet import defer | ||
| from twisted.internet.defer import Deferred | ||
|
|
@@ -174,7 +174,9 @@ def check_yield_points_inner( | |
| ) | ||
| ) | ||
| changes.append(err) | ||
| return getattr(e, "value", None) | ||
| # The `StopIteration` or `_DefGen_Return` contains the return value from the | ||
| # generator. | ||
| return cast(T, e.value) | ||
|
Comment on lines
-177
to
+179
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of the exception types we catch here have a class StopIteration(Exception):
value: Any
class _DefGen_Return(BaseException):
def __init__(self, value: object) -> None:
self.value = valueSince the exception comes from the generator
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Seems plausible: https://github.com/twisted/twisted/blob/5c24e99e671c4082a1ddc8dbeb869402294bd0dc/src/twisted/internet/defer.py#L1508-L1521 |
||
|
|
||
| frame = gen.gi_frame | ||
|
|
||
|
|
||
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 previous version of mypy didn't think .__attrs_attrs__ was a real attribute.
mypy 0.931 thinks it is, and thinks that
attributeis anobject, which doesn't have a .name.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.
Would mypy be happier with
attrs.fields_dicthere? Requires attrs 18.1.(Probably fine as-is though.)
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.
That's a little cleaner, thanks! We already require attrs>=19.2.0 so it's fine to use.
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 still looks a bit odd to have the getattr call. Maybe
get_sourcescould boil down toyield from attrs.asdict(self).items()? Actually, I think not: looks like one is supposed to inherit from_EventSourcesInner?I'm happy with this as it stands.