Skip to content

Commit

Permalink
Ugly hack to fix mypy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Apr 23, 2024
1 parent 8ee9740 commit d1f9e28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
26 changes: 26 additions & 0 deletions .github/workflows/types.yml
Original file line number Diff line number Diff line change
@@ -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 .
9 changes: 4 additions & 5 deletions huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d1f9e28

Please sign in to comment.