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 |
jakkdl
left a comment
There was a problem hiding this comment.
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.
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.
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.
Are you referring to #2740 (comment) ?
I removed the -> None without any impact on verify_types.json
| } | ||
|
|
||
| def __getattr__(self, name): | ||
| def __getattr__(self, name: str) -> Any: |
There was a problem hiding this comment.
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 |
jakkdl
left a comment
There was a problem hiding this comment.
oops nvm, the ambiguous type is still not resolved
A5rocks
left a comment
There was a problem hiding this comment.
Seems mostly good, just a couple things that jumped out at me (most aren't even typing-related).
jakkdl
left a comment
There was a problem hiding this comment.
+1 to a5rock on leaving __slots__ to separate PR as they've been controversial, otherwise seems ready to merge.
This reverts commit 3406eaf.
Apparently already being handled in python-trio#2756
This reverts commit 40e9bf2.
| server_hostname: str | None = None, | ||
| server_side: bool = False, | ||
| https_compatible: bool = False, | ||
| ) -> None: |
| 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.
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.
FWIW this -> None is probably also unnecessary.
There was a problem hiding this comment.
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.pyThree interesting thins I noticed when making sure the type annotations were good:
trio.abc.Listenernot using itsT_resourcegeneric in accept, now fixedSSLStream.receive_somecould have potentially returnedNoneif my typing forSSLStream._retryis correct. I don't think this is entirely true, I think everything is supposed to raise atrio.BrokenResourceErrorexception, but if it raised something else it could have returnedNone. There is a type-narrowingassert not Nonethere now, but I am curious if anyone has more information.SSLStream.unwrapsetsself.transport_streamtoNone, and nothing else checks to make sure it's notNoneanywhere. 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_streamto 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.