From d1f9e280fdf57b2f145fa896c095128ea752cab5 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Tue, 23 Apr 2024 12:28:38 +0800 Subject: [PATCH] Ugly hack to fix mypy warnings --- .github/workflows/main.yml | 5 +---- .github/workflows/types.yml | 26 ++++++++++++++++++++++++++ huffman.py | 9 ++++----- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/types.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 348332e..8ef4af3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,10 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest mypy + pip install pytest - name: Run tests run: | pytest tests/ - # - name: Check types with mypy - # run: | - # mypy . diff --git a/.github/workflows/types.yml b/.github/workflows/types.yml new file mode 100644 index 0000000..637e0fa --- /dev/null +++ b/.github/workflows/types.yml @@ -0,0 +1,26 @@ +name: Types + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install mypy pyright + - name: Check types with mypy + run: | + mypy . + - name: Check types with pyright + run: | + pyright . diff --git a/huffman.py b/huffman.py index 6927b44..8166a01 100755 --- a/huffman.py +++ b/huffman.py @@ -17,8 +17,6 @@ import functools -from typing import Optional - FREQUENCY_TABLE = [ 1 << 30, 4545, 2657, 431, 1950, 919, 444, 482, 2244, 617, 838, 542, 715, 1814, 304, 240, 754, 212, 647, 186, @@ -225,19 +223,20 @@ def decompress(self, data: bytes) -> bytes: bits = 0 bitcount = 0 eof = self.nodes[HUFFMAN_EOF_SYMBOL] - node: Optional[Node] = None + node = Node(0, 0, 0) while True: - node = None + found_node = False if bitcount >= HUFFMAN_LUTBITS: node = self.decoded_lut[bits & HUFFMAN_LUTMASK] + found_node = True while bitcount < 24 and src_index < size: bits |= data[src_index] << bitcount src_index += 1 bitcount += 8 - if not node: + if not found_node: node = self.decoded_lut[bits & HUFFMAN_LUTMASK] if node.num_bits != 0: