-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Add type annotations for _ssl.py
#2745
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2745 +/- ##
=======================================
Coverage 98.94% 98.94%
=======================================
Files 113 113
Lines 16837 16843 +6
Branches 3036 3036
=======================================
+ Hits 16659 16665 +6
Misses 123 123
Partials 55 55
|
Oops, didn't mean to click single comment. I think that + moving the |
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.
Guess which file needs to be updated...? pyproject.toml
!
Does your setup not use it for enabling checks? In my workflow I first need to update pyproject.toml
in order to be able to get the errors and see what needs fixing.
Otherwise mostly just nits
server_hostname: str | None = None, | ||
server_side: bool = False, | ||
https_compatible: bool = False, | ||
) -> 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.
nit: inconsequential -> None
. We ought to create a style guide somewhere for typing, and/or add a check to #2744 that removes/adds it.
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 is not inconsequential, I am fairly certain that verify_types.json
changes for the better when it's there
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.
Are you referring to #2740 (comment) ?
I removed the -> None
without any impact on verify_types.json
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.
Just bumping on this!
@@ -399,7 +410,7 @@ def __init__( | |||
"version", | |||
} | |||
|
|||
def __getattr__(self, name): | |||
def __getattr__(self, name: str) -> 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.
I suppose there's a case for returning object
here to tell the user they need to do isinstance
. But they can also enable disallow_any_expression
I suppose.
I tried finding an authoritative best-practice of what to do in this case, but no dice
How should this issue with readthedocs be addressed? /home/docs/checkouts/readthedocs.org/user_builds/trio/checkouts/2745/trio/abc.py:docstring of trio.abc.Listener.accept:1: WARNING: py:class reference target not found: trio._abc.T_resource |
You've got to add it to the ignore list 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.
oops nvm, the ambiguous type is still not resolved
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.
Seems mostly good, just a couple things that jumped out at me (most aren't even typing-related).
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.
+1 to a5rock on leaving __slots__
to separate PR as they've been controversial, otherwise seems ready to merge.
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.
Just a couple comments.
This reverts commit 3406eaf.
Apparently already being handled in python-trio#2756
This reverts commit 40e9bf2.
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.
Just some comments!
server_hostname: str | None = None, | ||
server_side: bool = False, | ||
https_compatible: bool = False, | ||
) -> 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.
Just bumping on this!
self._incoming = _stdlib_ssl.MemoryBIO() | ||
self._ssl_object = ssl_context.wrap_bio( | ||
self._incoming, | ||
self._outgoing, | ||
server_side=server_side, | ||
server_hostname=server_hostname, | ||
server_hostname=server_hostname, # type: ignore[arg-type] # Typeshed bug, does accept bytes as well (typeshed#10590) |
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.
Looks like that PR was merged, meaning next mypy release should support this! Nice!
https_compatible=False, | ||
): | ||
https_compatible: bool = False, | ||
) -> 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.
FWIW this -> None
is probably also unnecessary.
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 haven't seen any reason why it would change anything.
merging main ...
🚀 🚀 although it seems to think some symbols that are in fact public aren't, so it's partly a lie |
# Conflicts: # pyproject.toml # trio/_tests/verify_types.json
This PR adds type annotations to
_ssl.py
Three interesting thins I noticed when making sure the type annotations were good:
trio.abc.Listener
not using itsT_resource
generic in accept, now fixedSSLStream.receive_some
could have potentially returnedNone
if my typing forSSLStream._retry
is correct. I don't think this is entirely true, I think everything is supposed to raise atrio.BrokenResourceError
exception, but if it raised something else it could have returnedNone
. There is a type-narrowingassert not None
there now, but I am curious if anyone has more information.SSLStream.unwrap
setsself.transport_stream
toNone
, and nothing else checks to make sure it's notNone
anywhere. I assume this is ok since it also sets the internal state toCLOSED
, so I put a type ignore there to silence the error. The reason I hesitate to allowself.transport_stream
to be None is because the docstring says it's required to be a Stream object.I would love feedback and any comments on how this could be improved to be more accurate.