Browse Source

pipeline: run pylint

Fabian Peter Hammerle 2 weeks ago
parent
commit
8b1ed96620
4 changed files with 17 additions and 8 deletions
  1. 3 0
      .github/workflows/python.yml
  2. 0 4
      .pylintrc
  3. 13 4
      tooncher/__init__.py
  4. 1 0
      tooncher/_cli.py

+ 3 - 0
.github/workflows/python.yml

@@ -51,4 +51,7 @@ jobs:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
     - run: pipenv run pytest --cov=tooncher --cov-report=term-missing --cov-fail-under=63
+    - run: pipenv run pylint --load-plugins=pylint_import_requirements tooncher
+    # https://github.com/PyCQA/pylint/issues/352
+    - run: pipenv run pylint tests/*
     - run: pipenv run mypy tooncher tests

+ 0 - 4
.pylintrc

@@ -1,7 +1,3 @@
-[MASTER]
-
-load-plugins=pylint_import_requirements
-
 [MESSAGES CONTROL]
 
 disable=bad-continuation,

+ 13 - 4
tooncher/__init__.py

@@ -53,20 +53,29 @@ def _api_request(
         data=urllib.parse.urlencode(params).encode("ascii") if params else None,
         headers={"User-Agent": "tooncher"},
     )
-    response = urllib.request.urlopen(
-        request,
-        context=None if validate_ssl_cert else ssl._create_unverified_context(),
-    )
+    if validate_ssl_cert is False:  # explicit check to avoid catching None
+        # > To revert to [...] unverified behavior ssl._create_unverified_context()
+        # > can be passed to the context parameter.
+        # https://docs.python.org/3.8/library/http.client.html
+        ssl_context: typing.Optional[ssl.SSLContext] = (
+            # pylint: disable=protected-access; recommended in python docs
+            ssl._create_unverified_context()
+        )
+    else:
+        ssl_context = None
+    response = urllib.request.urlopen(request, context=ssl_context)
     return json.loads(response.read().decode("ascii"))
 
 
 class _LoginSuccessful:
+    # pylint: disable=too-few-public-methods; dataclass
     def __init__(self, playcookie: str, gameserver: str):
         self.playcookie = playcookie
         self.gameserver = gameserver
 
 
 class _LoginDelayed:
+    # pylint: disable=too-few-public-methods; dataclass
     def __init__(self, queue_token: str):
         self.queue_token = queue_token
 

+ 1 - 0
tooncher/_cli.py

@@ -59,6 +59,7 @@ def run(
 
 class _EnvDefaultArgparser(argparse.ArgumentParser):
     def add_argument(self, *args, envvar=None, **kwargs):
+        # pylint: disable=arguments-differ; using *args & **kwargs to catch all
         if envvar:
             envvar_value = os.environ.get(envvar, None)
             if envvar_value: