-
Notifications
You must be signed in to change notification settings - Fork 119
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
Use inline type hint syntax #381
Conversation
Looks like flake8 is displeased. |
Codecov Report
@@ Coverage Diff @@
## master #381 +/- ##
=======================================
Coverage 98.36% 98.36%
=======================================
Files 46 46
Lines 3909 3910 +1
Branches 256 256
=======================================
+ Hits 3845 3846 +1
Misses 46 46
Partials 18 18
Continue to review full report at Codecov.
|
@@ -37,14 +32,96 @@ class TransactionEnded(Exception): | |||
""" | |||
|
|||
|
|||
class SessionMechanism(Names): |
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.
Moved class def up so that it's defined before it is used (as a type) later in this file.
if TYPE_CHECKING: # pragma: no cover | ||
from ._requirer import RequestLifecycle | ||
|
||
IRequestLifecycleT = Union[RequestLifecycle, "IRequestLifecycle"] |
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.
Getting rid of IRequestLifecycleT
for consistency in how we handle internal type hacking currently for zope.interface
, see _IRequestLifecycle
def below.
class _IRequestLifecycle(Interface): | ||
""" | ||
Interface for adding hooks to the phases of a request's lifecycle. | ||
""" | ||
|
||
|
||
if TYPE_CHECKING: | ||
from typing import Union | ||
from ._requirer import RequestLifecycle | ||
|
||
IRequestLifecycle = Union[_IRequestLifecycle, RequestLifecycle] | ||
else: | ||
IRequestLifecycle = _IRequestLifecycle |
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.
When type checking, we use a Union
to work around lack of support for zone.interface
in Mypy.
Normally we do this in interfaces.py
, but we're doing it here (also) due to the fact that we use IRequestLifecycle
later in this file and importing from interfaces.py
will cause a circular import loop.
All of this should go away when we start using the Zope plug-in for Mypy.
@@ -22,61 +22,61 @@ | |||
) | |||
|
|||
if TYPE_CHECKING: # pragma: no cover |
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.
Most of this diff is sorting the file for later sanity.
We do remove import IRequestLifecycleT as _IRequestLifecycleT
and replace that with similar handling of other interfaces for consistency.
@twisted/kleiniforms I'd really like to knock this PR out since it touches everything and so I'm not going anything else because conflicts. Since it's all (with one exception) a very robotic moving of type refs from one form to another, and pretty well-validated by The one exception is in |
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.
This patch spans many files, but the changes are mostly mechanical changes to use the type annotation syntax for variables and functions/methods.
I raised a few minor questions, but no blockers, so I would suggest to merge this when you can and
resolve other issues later.
isConfidential = Attribute( | ||
""" | ||
A L{bool} indicating whether this session mechanism transmitted over an | ||
encrypted transport, i.e., HTTPS. If C{True}, this means that this |
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.
Should this be L{True}
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.
yup
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.
There's a lot of this. Will save for another PR.
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.
@rodrigc Thanks! I'll clean up what I can here. |
Use inline type hint syntax
Replace
Text
withstr
.Note that
_strategies.py
is intentionally excluded here because it's moving tohyperlink
and keeping that diff smaller seems like a better move.This is a very large diff, but the vast majority of it is mechanical conversation from comment-based type syntax to inline syntax, which is possible now that we require Python 3.6+. There is some slightly more interesting change in
_isession.py
due to the fact that the inline syntax causes the interpreter to notice things at runtime that it didn't in the comments; that is noted in review comments.