Skip to content

Commit

Permalink
Improve typing suggestions for MyPy compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
Privat33r-dev committed Aug 10, 2024
1 parent 88a0b3e commit 59f07a3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions clairvoyance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ async def post(
return await response.json(content_type=None)

except (
aiohttp.client_exceptions.ClientConnectionError,
aiohttp.client_exceptions.ClientPayloadError,
aiohttp.ClientConnectionError,
aiohttp.ClientPayloadError,
asyncio.TimeoutError,
json.decoder.JSONDecodeError,
) as e:
Expand Down
14 changes: 7 additions & 7 deletions clairvoyance/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Schema:

def __init__(
self,
query_type: str = None,
mutation_type: str = None,
subscription_type: str = None,
schema: Dict[str, Any] = None,
query_type: Optional[str] = None,
mutation_type: Optional[str] = None,
subscription_type: Optional[str] = None,
schema: Optional[Dict[str, Any]] = None,
):
if schema:
self._schema = {
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_path_from_root(

def get_type_without_fields(
self,
ignored: Set[str] = None,
ignored: Optional[Set[str]] = None,
) -> str:
"""Gets the type without a field."""
ignored = ignored or set()
Expand Down Expand Up @@ -331,7 +331,7 @@ def __init__(
self,
name: str,
typeref: Optional[TypeRef],
args: List[InputValue] = None,
args: Optional[List[InputValue]] = None,
):
if not typeref:
raise ValueError(f"Can't create {name} Field from {typeref} TypeRef.")
Expand Down Expand Up @@ -367,7 +367,7 @@ def __init__(
self,
name: str = "",
kind: str = "",
fields: List[Field] = None,
fields: Optional[List[Field]] = None,
):
self.name = name
self.kind = kind
Expand Down
8 changes: 4 additions & 4 deletions clairvoyance/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ async def __probation(document: str) -> Optional[graphql.TypeRef]:
error["message"],
context,
)

log().debug(f'get_typeref("{error["message"]}", "{context}") -> {typeref}')
if typeref:
log().debug(
f'get_typeref("{error["message"]}", "{context}") -> {typeref}'
)
return typeref

return None
Expand Down Expand Up @@ -582,7 +582,7 @@ async def explore_field(
async def clairvoyance(
wordlist: List[str],
input_document: str,
input_schema: Dict[str, Any] = None,
input_schema: Optional[Dict[str, Any]] = None,
) -> str:

log().debug(f"input_document = {input_document}")
Expand Down
3 changes: 2 additions & 1 deletion tests/server/graphql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http.server
import json
from typing import Optional


class UnstableHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
Expand All @@ -24,7 +25,7 @@ def log_message(self, format, *args) -> None: # type: ignore[no-untyped-def] #
pass


def main(port: int = None) -> None:
def main(port: Optional[int] = None) -> None:
port = port or 8081
with http.server.HTTPServer(("", port), UnstableHTTPRequestHandler) as httpd:
httpd.serve_forever()
Expand Down
3 changes: 2 additions & 1 deletion tests/server/unstable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http.server
import json
import os
from typing import Optional


class UnstableHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
Expand All @@ -23,7 +24,7 @@ def log_message(self, format, *args) -> None: # type: ignore[no-untyped-def] #
pass


def main(port: int = None) -> None:
def main(port: Optional[int] = None) -> None:
port = port or 8000
with http.server.HTTPServer(("", port), UnstableHTTPRequestHandler) as httpd:
httpd.serve_forever()
Expand Down
4 changes: 2 additions & 2 deletions tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUpClass(cls) -> None:
def query_type(self) -> Any:
query_type = self.get_type(self.schema["queryType"]["name"])
if not query_type:
raise Exception("Schema don't contain query type")
raise RuntimeError("Schema don't contain query type")

return query_type

Expand All @@ -56,7 +56,7 @@ def get_type(self, name: str) -> Optional[Dict[str, Any]]:

return None

def test_validate_wordlist(self):
def test_validate_wordlist(self) -> None:
self.assertIn(b"Removed 1 items from wordlist", self.clairvoyance.stderr)

def test_found_root_type_names(self) -> None:
Expand Down

0 comments on commit 59f07a3

Please sign in to comment.