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

Enable MyPy, PyLint #105

Merged
merged 7 commits into from
Aug 11, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ jobs:
run: |
source .venv/bin/activate
isort -m 9 --line-length 160 $MODULE_NAME tests --gitignore --check-only
# pylint $MODULE_NAME tests
pylint $MODULE_NAME tests
docformatter --wrap-summaries 160 --wrap-descriptions 160 -cr $MODULE_NAME tests
black --check $MODULE_NAME tests
mypy -V
# mypy $MODULE_NAME tests
mypy $MODULE_NAME tests
2 changes: 1 addition & 1 deletion clairvoyance/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_default_wordlist() -> List[str]:
return [w.strip() for w in f.readlines() if w.strip()]


async def blind_introspection(
async def blind_introspection( # pylint: disable=too-many-arguments
url: str,
logger: logging.Logger,
wordlist: List[str],
Expand Down
6 changes: 3 additions & 3 deletions clairvoyance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from clairvoyance.entities.interfaces import IClient


class Client(IClient):
class Client(IClient): # pylint: disable=too-many-instance-attributes
def __init__(
self,
url: str,
Expand Down 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
12 changes: 6 additions & 6 deletions clairvoyance/entities/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

# Quick resolve the context variables using macros.
config: Callable[..., IConfig] = (
lambda: config_ctx.get()
) # pylint: disable=unnecessary-lambda
lambda: config_ctx.get() # pylint: disable=unnecessary-lambda
)
client: Callable[..., IClient] = (
lambda: client_ctx.get()
) # pylint: disable=unnecessary-lambda
lambda: client_ctx.get() # pylint: disable=unnecessary-lambda
)
log: Callable[..., logging.Logger] = (
lambda: logger_ctx.get()
) # pylint: disable=unnecessary-lambda
lambda: logger_ctx.get() # pylint: disable=unnecessary-lambda
)
6 changes: 4 additions & 2 deletions clairvoyance/entities/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ async def post(
self,
document: Optional[str],
retries: int = 0,
) -> Dict: ...
) -> Dict:
pass

@abstractmethod
async def close(self) -> None: ...
async def close(self) -> None:
pass
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
3 changes: 1 addition & 2 deletions clairvoyance/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ async def __probation(document: str) -> Optional[graphql.TypeRef]:
error["message"],
context,
)

log().debug(f'get_typeref("{error["message"]}", "{context}") -> {typeref}')
if typeref:
return typeref
Expand Down Expand Up @@ -582,7 +581,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
4 changes: 2 additions & 2 deletions tests/graphql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class TestPost(aiounittest.AsyncTestCase):
def setUpClass(cls) -> None:
Client("http://localhost:8000/graphql")

cls._unstable = subprocess.Popen(
cls._unstable = subprocess.Popen( # pylint: disable=consider-using-with
["python3", "tests/server/unstable.py"]
) # pylint: disable=consider-using-with
)
time.sleep(1)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/oracle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ class TestProbeTypename(aiounittest.AsyncTestCase):
def setUpClass(cls) -> None:
Client("http://localhost:8081/graphql")

cls._unstable = subprocess.Popen(
cls._unstable = subprocess.Popen( # pylint: disable=consider-using-with
["python3", "tests/server/graphql.py"]
) # pylint: disable=consider-using-with
)
time.sleep(1)

@classmethod
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