Skip to content

Commit cdcb48b

Browse files
authored
Prune redundant :rtype: from SSL module (#1315)
The `SSL` module now has full type annotations, which are correctly extracted to the docs, so using `:rtype:` in the docstring is redundant. We also update the contributor guidelines to require type hints in new code.
1 parent b86914d commit cdcb48b

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

CONTRIBUTING.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ Documentation
3939

4040
When introducing new functionality, please remember to write documentation.
4141

42-
- New functions and methods should have a docstring describing what they do, what parameters they takes, what types those parameters are, and what they return.
42+
- New functions and methods should have a docstring describing what they do, what parameters they takes, and what they return. They should also come with `type hints`_.
4343

4444
.. code-block:: python
4545
46-
def dump_publickey(type, pkey):
46+
def dump_publickey(type: int, pkey: PKey) -> bytes:
4747
"""
4848
Dump a public key to a buffer.
4949
5050
:param type: The file type (one of :data:`FILETYPE_PEM` or
5151
:data:`FILETYPE_ASN1`).
52-
:param PKey pkey: The PKey to dump.
52+
:param pkey: The PKey to dump.
5353
5454
:return: The buffer with the dumped key in it.
55-
:rtype: bytes
5655
"""
5756
5857
@@ -110,6 +109,7 @@ Feel free to cross-check this information with Keybase_.
110109
.. _Keybase: https://keybase.io/hynek
111110
.. _pyca/pyopenssl: https://github.com/pyca/pyopenssl
112111
.. _PEP 8: https://www.python.org/dev/peps/pep-0008/
112+
.. _`type hints`: https://docs.python.org/3/library/typing.html
113113
.. _cryptography code review process: https://cryptography.io/en/latest/development/reviewing-patches/
114114
.. _freenode: https://freenode.net
115115
.. _mailing list: https://mail.python.org/mailman/listinfo/cryptography-dev

src/OpenSSL/SSL.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,6 @@ def renegotiate(self) -> bool:
22212221
Renegotiate the session.
22222222
22232223
:return: True if the renegotiation can be started, False otherwise
2224-
:rtype: bool
22252224
"""
22262225
if not self.renegotiate_pending():
22272226
_openssl_assert(_lib.SSL_renegotiate(self._ssl) == 1)
@@ -2245,7 +2244,6 @@ def renegotiate_pending(self) -> bool:
22452244
a renegotiation is finished.
22462245
22472246
:return: Whether there's a renegotiation in progress
2248-
:rtype: bool
22492247
"""
22502248
return _lib.SSL_renegotiate_pending(self._ssl) == 1
22512249

@@ -2254,7 +2252,6 @@ def total_renegotiations(self) -> int:
22542252
Find out the total number of renegotiations.
22552253
22562254
:return: The number of renegotiations.
2257-
:rtype: int
22582255
"""
22592256
return _lib.SSL_total_renegotiations(self._ssl)
22602257

@@ -2483,7 +2480,6 @@ def get_state_string(self) -> bytes:
24832480
Retrieve a verbose string detailing the state of the Connection.
24842481
24852482
:return: A string representing the state
2486-
:rtype: bytes
24872483
"""
24882484
return _ffi.string(_lib.SSL_state_string_long(self._ssl))
24892485

@@ -2724,7 +2720,6 @@ def _get_finished_message(self, function) -> Optional[bytes]:
27242720
27252721
:return: :data:`None` if the desired message has not yet been
27262722
received, otherwise the contents of the message.
2727-
:rtype: :class:`bytes` or :class:`NoneType`
27282723
"""
27292724
# The OpenSSL documentation says nothing about what might happen if the
27302725
# count argument given is zero. Specifically, it doesn't say whether
@@ -2754,7 +2749,6 @@ def get_finished(self) -> Optional[bytes]:
27542749
27552750
:return: The contents of the message or :obj:`None` if the TLS
27562751
handshake has not yet completed.
2757-
:rtype: :class:`bytes` or :class:`NoneType`
27582752
27592753
.. versionadded:: 0.15
27602754
"""
@@ -2766,7 +2760,6 @@ def get_peer_finished(self) -> Optional[bytes]:
27662760
27672761
:return: The contents of the message or :obj:`None` if the TLS
27682762
handshake has not yet completed.
2769-
:rtype: :class:`bytes` or :class:`NoneType`
27702763
27712764
.. versionadded:: 0.15
27722765
"""
@@ -2778,7 +2771,6 @@ def get_cipher_name(self) -> Optional[str]:
27782771
27792772
:returns: The name of the currently used cipher or :obj:`None`
27802773
if no connection has been established.
2781-
:rtype: :class:`str` or :class:`NoneType`
27822774
27832775
.. versionadded:: 0.15
27842776
"""
@@ -2795,7 +2787,6 @@ def get_cipher_bits(self) -> Optional[int]:
27952787
27962788
:returns: The number of secret bits of the currently used cipher
27972789
or :obj:`None` if no connection has been established.
2798-
:rtype: :class:`int` or :class:`NoneType`
27992790
28002791
.. versionadded:: 0.15
28012792
"""
@@ -2811,7 +2802,6 @@ def get_cipher_version(self) -> Optional[str]:
28112802
28122803
:returns: The protocol name of the currently used cipher
28132804
or :obj:`None` if no connection has been established.
2814-
:rtype: :class:`str` or :class:`NoneType`
28152805
28162806
.. versionadded:: 0.15
28172807
"""
@@ -2829,7 +2819,6 @@ def get_protocol_version_name(self) -> str:
28292819
:returns: The TLS version of the current connection, for example
28302820
the value for TLS 1.2 would be ``TLSv1.2``or ``Unknown``
28312821
for connections that were not successfully established.
2832-
:rtype: :class:`str`
28332822
"""
28342823
version = _ffi.string(_lib.SSL_get_version(self._ssl))
28352824
return version.decode("utf-8")
@@ -2840,7 +2829,6 @@ def get_protocol_version(self) -> int:
28402829
28412830
:returns: The TLS version of the current connection. For example,
28422831
it will return ``0x769`` for connections made over TLS version 1.
2843-
:rtype: :class:`int`
28442832
"""
28452833
version = _lib.SSL_version(self._ssl)
28462834
return version

0 commit comments

Comments
 (0)