From b572689107745241c300e023cf28032a4d9c2f47 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 20 Aug 2021 18:10:07 +0000 Subject: [PATCH] Apply more rigorous type checking, fix a few bugs caught with that more rigorous type checking. --- bemani/backend/dispatch.py | 3 ++- bemani/format/afp/decompile.py | 2 +- bemani/format/afp/util.py | 2 +- bemani/frontend/admin/admin.py | 4 ++-- bemani/utils/proxy.py | 8 ++++++-- bemani/utils/services.py | 2 -- verifytyping | 12 ++++++++++++ 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/bemani/backend/dispatch.py b/bemani/backend/dispatch.py index 732f8a0..97eb031 100644 --- a/bemani/backend/dispatch.py +++ b/bemani/backend/dispatch.py @@ -1,6 +1,7 @@ from typing import Optional, Any -from bemani.backend.base import Model, Base, Status +from bemani.backend.base import Base, Status +from bemani.common import Model from bemani.protocol import Node from bemani.data import Config, Data diff --git a/bemani/format/afp/decompile.py b/bemani/format/afp/decompile.py index fb480fe..4cde68a 100644 --- a/bemani/format/afp/decompile.py +++ b/bemani/format/afp/decompile.py @@ -2634,8 +2634,8 @@ class ByteCodeDecompiler(VerboseOutput): if isinstance(statement, GotoStatement): if statement.location in labels: - return NullReturnStatement() updated = True + return NullReturnStatement() return statement statements = self.__walk(statements, update_gotos) diff --git a/bemani/format/afp/util.py b/bemani/format/afp/util.py index 6dbb469..bb68e13 100644 --- a/bemani/format/afp/util.py +++ b/bemani/format/afp/util.py @@ -73,7 +73,7 @@ class TrackedCoverage: def get_uncovered_chunks(self, req_start: Optional[int] = None, req_end: Optional[int] = None, adjust_offsets: bool = False) -> List[Tuple[int, int]]: # First offset that is not coverd in a run. - start = None + start: Optional[int] = None chunks: List[Tuple[int, int]] = [] for offset, covered in enumerate(self.coverage): diff --git a/bemani/frontend/admin/admin.py b/bemani/frontend/admin/admin.py index 3022c0d..84535bd 100644 --- a/bemani/frontend/admin/admin.py +++ b/bemani/frontend/admin/admin.py @@ -631,8 +631,8 @@ def generatepcbid() -> Dict[str, Any]: raise Exception('Unable to find arcade to link PCBID to!') # Will be set by the game on boot. - name = 'なし' - pcbid = None + name: str = 'なし' + pcbid: Optional[str] = None while pcbid is None: # Generate a new PCBID, check for uniqueness potential_pcbid = "01201000000000" + "".join([random.choice("0123456789ABCDEF") for _ in range(6)]) diff --git a/bemani/utils/proxy.py b/bemani/utils/proxy.py index f2d8948..5aac21a 100644 --- a/bemani/utils/proxy.py +++ b/bemani/utils/proxy.py @@ -165,10 +165,14 @@ def receive_request(path: str) -> Response: } # Copy over required headers that are sent by game client. - if request_compression is not None: + if request_compression: headers['X-Compress'] = request_compression - if request_encryption is not None: + else: + headers['X-Compress'] = 'none' + if request_encryption: headers['X-Eamuse-Info'] = request_encryption + + # Make sure to copy the user agent as well. if request_client is not None: headers['User-Agent'] = request_client diff --git a/bemani/utils/services.py b/bemani/utils/services.py index ed4964e..2aaf647 100644 --- a/bemani/utils/services.py +++ b/bemani/utils/services.py @@ -68,8 +68,6 @@ def receive_request(path: str) -> Response: ) return Response("No response generated", 404) - compression = None - data = proto.encode( compression, encryption, diff --git a/verifytyping b/verifytyping index 478ba1f..f989aba 100755 --- a/verifytyping +++ b/verifytyping @@ -41,9 +41,21 @@ MYPYPATH=$(python -c "import os; print(os.path.realpath('.'))") mypy \ "${cmdline[@]}" \ --warn-redundant-casts \ --warn-unused-ignores \ + --warn-unused-configs \ + --warn-unreachable \ --disallow-untyped-calls \ --disallow-untyped-defs \ --disallow-subclassing-any \ --disallow-incomplete-defs \ + --disallow-untyped-decorators \ + --check-untyped-defs \ + --strict-equality \ + --no-implicit-reexport \ --no-implicit-optional \ --no-strict-optional + +# Currently we are missing the following options to make us "strict": +# --disallow-any-generics - Currently impossible to type certain generics such as Callable. +# --warn-return-any - This finds a lot of code that we know is correct but mypy can't prove, not worth it. +# We also would want to get rid of the following options: +# --no-strict-optional - We have a lot of code that doesn't check but should check for optional.