Skip to content

Commit 30972e5

Browse files
committed
Add type annotations
1 parent 313dff9 commit 30972e5

File tree

23 files changed

+185
-150
lines changed

23 files changed

+185
-150
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ virtualenv.py
3939
.install-deps
4040
.develop
4141
.idea/
42+
.vscode/
4243
usage*.py

python_socks/_abc.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
class SyncProxy:
2-
def connect(self, dest_host, dest_port, timeout=None, **kwargs):
3-
raise NotImplementedError()
4-
5-
@property
6-
def proxy_host(self):
7-
raise NotImplementedError()
8-
9-
@property
10-
def proxy_port(self):
11-
raise NotImplementedError()
1+
from typing import Optional
122

133

144
class AsyncProxy:
@@ -39,7 +29,7 @@ class SyncSocketStream:
3929
def write_all(self, data: bytes):
4030
raise NotImplementedError()
4131

42-
def read(self, max_bytes: int = None):
32+
def read(self, max_bytes: Optional[int] = None):
4333
raise NotImplementedError()
4434

4535
def read_exact(self, n: int):
@@ -53,7 +43,7 @@ class AsyncSocketStream:
5343
async def write_all(self, data: bytes):
5444
raise NotImplementedError()
5545

56-
async def read(self, max_bytes: int = None):
46+
async def read(self, max_bytes: Optional[int] = None):
5747
raise NotImplementedError()
5848

5949
async def read_exact(self, n: int):

python_socks/_connectors/factory_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from .._abc import AsyncResolver
23
from .._types import ProxyType
34

@@ -9,9 +10,9 @@
910

1011
def create_connector(
1112
proxy_type: ProxyType,
12-
username: str,
13-
password: str,
14-
rdns: bool,
13+
username: Optional[str],
14+
password: Optional[str],
15+
rdns: Optional[bool],
1516
resolver: AsyncResolver,
1617
) -> AsyncConnector:
1718
if proxy_type == ProxyType.SOCKS4:

python_socks/_connectors/factory_sync.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from .._abc import SyncResolver
23
from .._types import ProxyType
34

@@ -9,9 +10,9 @@
910

1011
def create_connector(
1112
proxy_type: ProxyType,
12-
username: str,
13-
password: str,
14-
rdns: bool,
13+
username: Optional[str],
14+
password: Optional[str],
15+
rdns: Optional[bool],
1516
resolver: SyncResolver,
1617
) -> SyncConnector:
1718
if proxy_type == ProxyType.SOCKS4:

python_socks/_connectors/http_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from .._abc import AsyncSocketStream, AsyncResolver
23
from .abc import AsyncConnector
34

@@ -7,8 +8,8 @@
78
class HttpAsyncConnector(AsyncConnector):
89
def __init__(
910
self,
10-
username: str,
11-
password: str,
11+
username: Optional[str],
12+
password: Optional[str],
1213
resolver: AsyncResolver,
1314
):
1415
self._username = username

python_socks/_connectors/http_sync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from .._abc import SyncSocketStream, SyncResolver
23
from .abc import SyncConnector
34

@@ -7,8 +8,8 @@
78
class HttpSyncConnector(SyncConnector):
89
def __init__(
910
self,
10-
username: str,
11-
password: str,
11+
username: Optional[str],
12+
password: Optional[str],
1213
resolver: SyncResolver,
1314
):
1415
self._username = username

python_socks/_connectors/socks4_async.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from typing import Optional
23

34
from .._abc import AsyncSocketStream, AsyncResolver
45
from .abc import AsyncConnector
@@ -10,8 +11,8 @@
1011
class Socks4AsyncConnector(AsyncConnector):
1112
def __init__(
1213
self,
13-
user_id: str,
14-
rdns: bool,
14+
user_id: Optional[str],
15+
rdns: Optional[bool],
1516
resolver: AsyncResolver,
1617
):
1718
if rdns is None:

python_socks/_connectors/socks4_sync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from typing import Optional
23

34
from .._abc import SyncSocketStream, SyncResolver
45
from .abc import SyncConnector
@@ -10,8 +11,8 @@
1011
class Socks4SyncConnector(SyncConnector):
1112
def __init__(
1213
self,
13-
user_id: str,
14-
rdns: bool,
14+
user_id: Optional[str],
15+
rdns: Optional[bool],
1516
resolver: SyncResolver,
1617
):
1718
if rdns is None:

python_socks/_connectors/socks5_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from typing import Optional
23

34
from .._abc import AsyncSocketStream, AsyncResolver
45
from .abc import AsyncConnector
@@ -10,9 +11,9 @@
1011
class Socks5AsyncConnector(AsyncConnector):
1112
def __init__(
1213
self,
13-
username: str,
14-
password: str,
15-
rdns: bool,
14+
username: Optional[str],
15+
password: Optional[str],
16+
rdns: Optional[bool],
1617
resolver: AsyncResolver,
1718
):
1819
if rdns is None:

python_socks/_connectors/socks5_sync.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from typing import Optional
23

34
from .._abc import SyncSocketStream, SyncResolver
45
from .abc import SyncConnector
@@ -10,9 +11,9 @@
1011
class Socks5SyncConnector(SyncConnector):
1112
def __init__(
1213
self,
13-
username: str,
14-
password: str,
15-
rdns: bool,
14+
username: Optional[str],
15+
password: Optional[str],
16+
rdns: Optional[bool],
1617
resolver: SyncResolver,
1718
):
1819
if rdns is None:

0 commit comments

Comments
 (0)