Skip to content

Commit c7d8896

Browse files
authored
Merge pull request #107 from amacfie/fix-implicit-optional
Fix "implicit optional", e.g. `arg: int = None`
2 parents 0e68ab3 + 0d09c9e commit c7d8896

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

asyncwhois/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def whois(
5050
authoritative_only: bool = False, # todo: deprecate and remove this argument
5151
find_authoritative_server: bool = True,
5252
ignore_not_found: bool = False,
53-
proxy_url: str = None,
53+
proxy_url: Optional[str] = None,
5454
timeout: int = 10,
5555
tldextract_obj: TLDExtract = None,
5656
) -> tuple[str, dict]:
@@ -148,7 +148,7 @@ async def aio_whois(
148148
authoritative_only: bool = False, # todo: deprecate and remove this argument
149149
find_authoritative_server: bool = True,
150150
ignore_not_found: bool = False,
151-
proxy_url: str = None,
151+
proxy_url: Optional[str] = None,
152152
timeout: int = 10,
153153
tldextract_obj: TLDExtract = None,
154154
) -> tuple[str, dict]:
@@ -267,7 +267,7 @@ def whois_domain(
267267
domain: str,
268268
authoritative_only: bool = False,
269269
ignore_not_found: bool = False,
270-
proxy_url: str = None,
270+
proxy_url: Optional[str] = None,
271271
timeout: int = 10,
272272
tldextract_obj: TLDExtract = None,
273273
) -> DomainLookup:
@@ -304,7 +304,7 @@ async def aio_whois_domain(
304304
domain: str,
305305
authoritative_only: bool = False,
306306
ignore_not_found: bool = False,
307-
proxy_url: str = None,
307+
proxy_url: Optional[str] = None,
308308
timeout: int = 10,
309309
tldextract_obj: TLDExtract = None,
310310
) -> DomainLookup:
@@ -398,7 +398,7 @@ async def aio_rdap_domain(
398398
def whois_ipv4(
399399
ipv4: Union[IPv4Address, str],
400400
authoritative_only: bool = False,
401-
proxy_url: str = None,
401+
proxy_url: Optional[str] = None,
402402
timeout: int = 10,
403403
) -> NumberLookup:
404404
"""
@@ -428,7 +428,7 @@ def whois_ipv4(
428428
async def aio_whois_ipv4(
429429
ipv4: Union[IPv4Address, str],
430430
authoritative_only: bool = False,
431-
proxy_url: str = None,
431+
proxy_url: Optional[str] = None,
432432
timeout: int = 10,
433433
) -> NumberLookup:
434434
"""
@@ -506,7 +506,7 @@ async def aio_rdap_ipv4(
506506
def whois_ipv6(
507507
ipv6: Union[IPv6Address, str],
508508
authoritative_only: bool = False,
509-
proxy_url: str = None,
509+
proxy_url: Optional[str] = None,
510510
timeout: int = 10,
511511
) -> NumberLookup:
512512
"""
@@ -536,7 +536,7 @@ def whois_ipv6(
536536
async def aio_whois_ipv6(
537537
ipv6: Union[IPv6Address, str],
538538
authoritative_only: bool = False,
539-
proxy_url: str = None,
539+
proxy_url: Optional[str] = None,
540540
timeout: int = 10,
541541
) -> NumberLookup:
542542
"""

asyncwhois/client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ipaddress
2-
from typing import Union, Any
2+
from typing import Union, Any, Optional
33

44
from tldextract.tldextract import extract, TLDExtract
55
import whodap
@@ -51,7 +51,7 @@ def __init__(
5151
authoritative_only: bool = False,
5252
find_authoritative_server: bool = True,
5353
ignore_not_found: bool = False,
54-
proxy_url: str = None,
54+
proxy_url: Optional[str] = None,
5555
whodap_client: whodap.DNSClient = None,
5656
timeout: int = 10,
5757
tldextract_obj: TLDExtract = None,
@@ -125,7 +125,7 @@ class NumberClient(Client):
125125
def __init__(
126126
self,
127127
authoritative_only: bool = False,
128-
proxy_url: str = None,
128+
proxy_url: Optional[str] = None,
129129
whodap_client: Union[whodap.IPv4Client, whodap.IPv6Client] = None,
130130
timeout: int = 10,
131131
):

asyncwhois/query.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ipaddress
33
import re
44
import socket
5-
from typing import Tuple, Generator, Union
5+
from typing import Tuple, Generator, Union, Optional
66
from contextlib import contextmanager, asynccontextmanager
77

88
from python_socks.sync import Proxy
@@ -21,7 +21,7 @@ class Query:
2121

2222
def __init__(
2323
self,
24-
proxy_url: str = None,
24+
proxy_url: Optional[str] = None,
2525
timeout: int = 10,
2626
find_authoritative_server: bool = True,
2727
):
@@ -39,7 +39,7 @@ def _find_match(regex: str, blob: str) -> str:
3939

4040
@contextmanager
4141
def _create_connection(
42-
self, address: Tuple[str, int], proxy_url: str = None
42+
self, address: Tuple[str, int], proxy_url: Optional[str] = None
4343
) -> Generator[socket.socket, None, None]:
4444
s = None
4545
try:
@@ -58,7 +58,7 @@ def _create_connection(
5858

5959
@asynccontextmanager
6060
async def _aio_create_connection(
61-
self, address: Tuple[str, int], proxy_url: str = None
61+
self, address: Tuple[str, int], proxy_url: Optional[str] = None
6262
) -> Generator[Tuple[asyncio.StreamReader, asyncio.StreamWriter], None, None]:
6363
# init
6464
reader, writer = None, None
@@ -107,7 +107,7 @@ async def _aio_send_and_recv(
107107
result += received.decode("utf-8", errors="ignore")
108108
return result
109109

110-
def run(self, search_term: str, server: str = None) -> list[str]:
110+
def run(self, search_term: str, server: Optional[str] = None) -> list[str]:
111111
"""
112112
Submits the `search_term` to the WHOIS server and returns a list of query responses.
113113
"""
@@ -133,7 +133,9 @@ def _continue_querying(current_server: str, next_server: str) -> bool:
133133
and not next_server.startswith("www.")
134134
)
135135

136-
async def aio_run(self, search_term: str, server: str = None) -> list[str]:
136+
async def aio_run(
137+
self, search_term: str, server: Optional[str] = None
138+
) -> list[str]:
137139
data = search_term + "\r\n"
138140
if not server:
139141
if ":" in data: # ipv6
@@ -201,8 +203,8 @@ async def _aio_do_query(
201203
class DomainQuery(Query):
202204
def __init__(
203205
self,
204-
server: str = None,
205-
proxy_url: str = None,
206+
server: Optional[str] = None,
207+
proxy_url: Optional[str] = None,
206208
timeout: int = 10,
207209
find_authoritative_server: bool = True,
208210
):
@@ -219,12 +221,14 @@ def _get_server_name(domain_name: str) -> Union[str, None]:
219221
return server
220222
return None
221223

222-
def run(self, search_term: str, server: str = None) -> list[str]:
224+
def run(self, search_term: str, server: Optional[str] = None) -> list[str]:
223225
if not server:
224226
server = self._get_server_name(search_term)
225227
return super().run(str(search_term), server)
226228

227-
async def aio_run(self, search_term: str, server: str = None) -> list[str]:
229+
async def aio_run(
230+
self, search_term: str, server: Optional[str] = None
231+
) -> list[str]:
228232
if not server:
229233
server = self._get_server_name(search_term)
230234
return await super().aio_run(str(search_term), server)
@@ -233,8 +237,8 @@ async def aio_run(self, search_term: str, server: str = None) -> list[str]:
233237
class NumberQuery(Query):
234238
def __init__(
235239
self,
236-
server: str = None,
237-
proxy_url: str = None,
240+
server: Optional[str] = None,
241+
proxy_url: Optional[str] = None,
238242
timeout: int = 10,
239243
):
240244
super().__init__(proxy_url, timeout)
@@ -252,7 +256,7 @@ def _get_server_name(ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address]):
252256
def run(
253257
self,
254258
search_term: Union[ipaddress.IPv4Address, ipaddress.IPv6Address],
255-
server: str = None,
259+
server: Optional[str] = None,
256260
) -> list[str]:
257261
if not server:
258262
server = self._get_server_name(search_term)
@@ -261,7 +265,7 @@ def run(
261265
async def aio_run(
262266
self,
263267
search_term: Union[ipaddress.IPv4Address, ipaddress.IPv6Address],
264-
server: str = None,
268+
server: Optional[str] = None,
265269
) -> list[str]:
266270
if not server:
267271
server = self._get_server_name(search_term)

asyncwhois/tldparsers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""TLD-specific domain parser classes
2-
"""
1+
"""TLD-specific domain parser classes"""
32

43
from datetime import datetime
54
import re

0 commit comments

Comments
 (0)