Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "implicit optional", e.g. arg: int = None #107

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions asyncwhois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def whois(
authoritative_only: bool = False, # todo: deprecate and remove this argument
find_authoritative_server: bool = True,
ignore_not_found: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
tldextract_obj: TLDExtract = None,
) -> tuple[str, dict]:
Expand Down Expand Up @@ -148,7 +148,7 @@ async def aio_whois(
authoritative_only: bool = False, # todo: deprecate and remove this argument
find_authoritative_server: bool = True,
ignore_not_found: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
tldextract_obj: TLDExtract = None,
) -> tuple[str, dict]:
Expand Down Expand Up @@ -267,7 +267,7 @@ def whois_domain(
domain: str,
authoritative_only: bool = False,
ignore_not_found: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
tldextract_obj: TLDExtract = None,
) -> DomainLookup:
Expand Down Expand Up @@ -304,7 +304,7 @@ async def aio_whois_domain(
domain: str,
authoritative_only: bool = False,
ignore_not_found: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
tldextract_obj: TLDExtract = None,
) -> DomainLookup:
Expand Down Expand Up @@ -398,7 +398,7 @@ async def aio_rdap_domain(
def whois_ipv4(
ipv4: Union[IPv4Address, str],
authoritative_only: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
) -> NumberLookup:
"""
Expand Down Expand Up @@ -428,7 +428,7 @@ def whois_ipv4(
async def aio_whois_ipv4(
ipv4: Union[IPv4Address, str],
authoritative_only: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
) -> NumberLookup:
"""
Expand Down Expand Up @@ -506,7 +506,7 @@ async def aio_rdap_ipv4(
def whois_ipv6(
ipv6: Union[IPv6Address, str],
authoritative_only: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
) -> NumberLookup:
"""
Expand Down Expand Up @@ -536,7 +536,7 @@ def whois_ipv6(
async def aio_whois_ipv6(
ipv6: Union[IPv6Address, str],
authoritative_only: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
) -> NumberLookup:
"""
Expand Down
6 changes: 3 additions & 3 deletions asyncwhois/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ipaddress
from typing import Union, Any
from typing import Union, Any, Optional

from tldextract.tldextract import extract, TLDExtract
import whodap
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(
authoritative_only: bool = False,
find_authoritative_server: bool = True,
ignore_not_found: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
whodap_client: whodap.DNSClient = None,
timeout: int = 10,
tldextract_obj: TLDExtract = None,
Expand Down Expand Up @@ -125,7 +125,7 @@ class NumberClient(Client):
def __init__(
self,
authoritative_only: bool = False,
proxy_url: str = None,
proxy_url: Optional[str] = None,
whodap_client: Union[whodap.IPv4Client, whodap.IPv6Client] = None,
timeout: int = 10,
):
Expand Down
32 changes: 18 additions & 14 deletions asyncwhois/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ipaddress
import re
import socket
from typing import Tuple, Generator, Union
from typing import Tuple, Generator, Union, Optional
from contextlib import contextmanager, asynccontextmanager

from python_socks.sync import Proxy
Expand All @@ -21,7 +21,7 @@ class Query:

def __init__(
self,
proxy_url: str = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
find_authoritative_server: bool = True,
):
Expand All @@ -39,7 +39,7 @@ def _find_match(regex: str, blob: str) -> str:

@contextmanager
def _create_connection(
self, address: Tuple[str, int], proxy_url: str = None
self, address: Tuple[str, int], proxy_url: Optional[str] = None
) -> Generator[socket.socket, None, None]:
s = None
try:
Expand All @@ -58,7 +58,7 @@ def _create_connection(

@asynccontextmanager
async def _aio_create_connection(
self, address: Tuple[str, int], proxy_url: str = None
self, address: Tuple[str, int], proxy_url: Optional[str] = None
) -> Generator[Tuple[asyncio.StreamReader, asyncio.StreamWriter], None, None]:
# init
reader, writer = None, None
Expand Down Expand Up @@ -107,7 +107,7 @@ async def _aio_send_and_recv(
result += received.decode("utf-8", errors="ignore")
return result

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

async def aio_run(self, search_term: str, server: str = None) -> list[str]:
async def aio_run(
self, search_term: str, server: Optional[str] = None
) -> list[str]:
data = search_term + "\r\n"
if not server:
if ":" in data: # ipv6
Expand Down Expand Up @@ -201,8 +203,8 @@ async def _aio_do_query(
class DomainQuery(Query):
def __init__(
self,
server: str = None,
proxy_url: str = None,
server: Optional[str] = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
find_authoritative_server: bool = True,
):
Expand All @@ -219,12 +221,14 @@ def _get_server_name(domain_name: str) -> Union[str, None]:
return server
return None

def run(self, search_term: str, server: str = None) -> list[str]:
def run(self, search_term: str, server: Optional[str] = None) -> list[str]:
if not server:
server = self._get_server_name(search_term)
return super().run(str(search_term), server)

async def aio_run(self, search_term: str, server: str = None) -> list[str]:
async def aio_run(
self, search_term: str, server: Optional[str] = None
) -> list[str]:
if not server:
server = self._get_server_name(search_term)
return await super().aio_run(str(search_term), server)
Expand All @@ -233,8 +237,8 @@ async def aio_run(self, search_term: str, server: str = None) -> list[str]:
class NumberQuery(Query):
def __init__(
self,
server: str = None,
proxy_url: str = None,
server: Optional[str] = None,
proxy_url: Optional[str] = None,
timeout: int = 10,
):
super().__init__(proxy_url, timeout)
Expand All @@ -252,7 +256,7 @@ def _get_server_name(ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address]):
def run(
self,
search_term: Union[ipaddress.IPv4Address, ipaddress.IPv6Address],
server: str = None,
server: Optional[str] = None,
) -> list[str]:
if not server:
server = self._get_server_name(search_term)
Expand All @@ -261,7 +265,7 @@ def run(
async def aio_run(
self,
search_term: Union[ipaddress.IPv4Address, ipaddress.IPv6Address],
server: str = None,
server: Optional[str] = None,
) -> list[str]:
if not server:
server = self._get_server_name(search_term)
Expand Down
3 changes: 1 addition & 2 deletions asyncwhois/tldparsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""TLD-specific domain parser classes
"""
"""TLD-specific domain parser classes"""

from datetime import datetime
import re
Expand Down
Loading