Skip to content

Commit ddbedf7

Browse files
committed
Added type annotations to utils and extras. Updated dev requirements, changelog
1 parent 1b01821 commit ddbedf7

File tree

7 files changed

+844
-655
lines changed

7 files changed

+844
-655
lines changed

Changelog.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Change Log
22
=============
33

4+
1.1.3
5+
++++++
6+
7+
Changes
8+
--------
9+
10+
* ``ssh2.utils.version()`` now returns a string.
11+
12+
Fixes
13+
-------
14+
15+
16+
417
1.1.2
518
++++++
619

requirements_dev.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cython
2-
flake8
2+
flake8>=3.0.0
3+
flake8-annotations
4+
flake-type-annotations-plugin
35
jinja2
46
pytest
57
pytest-rerunfailures

ssh2/extras.c

Lines changed: 167 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/extras.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
22
Additional functionality not part of the libssh2 API.
33
"""
4+
from typing import Callable
5+
46
from . cimport error_codes
57
from .utils import find_eol
68

79

8-
def eagain_errcode(func, poller_func, *args, **kwargs):
10+
def eagain_errcode(func: Callable, poller_func: Callable, *args, **kwargs):
911
"""Helper function for reading in non-blocking mode.
1012
1113
Any additional arguments and keyword arguments provided are used as arguments to the session function `func`.
@@ -24,7 +26,7 @@ def eagain_errcode(func, poller_func, *args, **kwargs):
2426
return ret
2527

2628

27-
def eagain_write_errcode(write_func, poller_func, bytes data):
29+
def eagain_write_errcode(write_func: Callable, poller_func: Callable, bytes data: bytes):
2830
"""Helper function for writing in non-blocking mode.
2931
3032
Any additional arguments and keyword arguments provided are used as arguments to the session function `write_func`.

ssh2/session.c

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/utils.c

Lines changed: 647 additions & 546 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssh2/utils.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616

1717
from select import select
18+
from typing import Iterable, Tuple
1819

1920
from cpython.version cimport PY_MAJOR_VERSION
2021

@@ -48,7 +49,7 @@ cdef object to_str_len(char *c_str, int length):
4849
return c_str[:length].decode(ENCODING)
4950

5051

51-
def find_eol(bytes buf, Py_ssize_t pos):
52+
def find_eol(bytes buf: bytes, Py_ssize_t pos: Py_ssize_t) -> Tuple(int, int):
5253
"""Find end-of-line in buffer from position and return end position of
5354
line and where next find_eol should start from.
5455
@@ -75,7 +76,7 @@ def find_eol(bytes buf, Py_ssize_t pos):
7576
return index, new_pos
7677

7778

78-
def readline(buf):
79+
def readline(buf: Iterable) -> Iterable:
7980
"""Returns a generator of line by line output in given iterable buffer.
8081

8182
:param buf: The iterable buffer to read from. Should yield a block of data per iteration.
@@ -109,7 +110,7 @@ def readline(buf):
109110
yield remainder
110111

111112

112-
def version(int required_version=0):
113+
def version(int required_version=0) -> str:
113114
"""Get libssh2 version string.
114115

115116
Passing in a non-zero required_version causes the function to return
@@ -123,16 +124,15 @@ def version(int required_version=0):
123124
version = c_ssh2.libssh2_version(required_version)
124125
if version is NULL:
125126
return
126-
return version
127+
return to_str(version)
127128

128129

129130
def ssh2_exit():
130131
"""Call libssh2_exit"""
131132
c_ssh2.libssh2_exit()
132133

133134

134-
135-
def wait_socket(_socket not None, Session session, timeout=1):
135+
def wait_socket(_socket not None, Session session: "Session", timeout=1):
136136
"""Helper function for testing non-blocking mode.
137137
138138
This function blocks the calling thread for <timeout> seconds -

0 commit comments

Comments
 (0)