From f9bc6f2d08781164e3eedbede926bab45a2aa8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 2 Nov 2023 14:46:38 +0100 Subject: [PATCH] Cleanup: fix mypy errors This mostly handles a mypy change where implicit optionals (i.e. things like `size: int = None`) are no longer allowed. No functional changes. --- blender_asset_tracer/blendfile/dna.py | 3 ++- blender_asset_tracer/pack/progress.py | 3 ++- blender_asset_tracer/pack/transfer.py | 3 ++- blender_asset_tracer/trace/result.py | 7 ++++--- tests/abstract_test.py | 4 ++++ tests/test_shaman_transfer.py | 7 +++++++ tests/test_tracer.py | 9 +++++---- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/blender_asset_tracer/blendfile/dna.py b/blender_asset_tracer/blendfile/dna.py index 061c894..381bb93 100644 --- a/blender_asset_tracer/blendfile/dna.py +++ b/blender_asset_tracer/blendfile/dna.py @@ -22,6 +22,7 @@ import logging import os import typing +from typing import Optional from . import header, exceptions @@ -104,7 +105,7 @@ class Struct: log = log.getChild("Struct") - def __init__(self, dna_type_id: bytes, size: int = None) -> None: + def __init__(self, dna_type_id: bytes, size: Optional[int] = None) -> None: """ :param dna_type_id: name of the struct in C, like b'AlembicObjectPath'. :param size: only for unit tests; typically set after construction by diff --git a/blender_asset_tracer/pack/progress.py b/blender_asset_tracer/pack/progress.py index aa364e1..ceac431 100644 --- a/blender_asset_tracer/pack/progress.py +++ b/blender_asset_tracer/pack/progress.py @@ -25,6 +25,7 @@ import logging import pathlib import queue import typing +from typing import Optional import blender_asset_tracer.trace.progress @@ -134,7 +135,7 @@ class ThreadSafeCallback(Callback): def missing_file(self, filename: pathlib.Path) -> None: self._queue(self.wrapped.missing_file, filename) - def flush(self, timeout: float = None) -> None: + def flush(self, timeout: Optional[float] = None) -> None: """Call the queued calls, call this in the main thread.""" while True: diff --git a/blender_asset_tracer/pack/transfer.py b/blender_asset_tracer/pack/transfer.py index 82a7125..b4e543c 100644 --- a/blender_asset_tracer/pack/transfer.py +++ b/blender_asset_tracer/pack/transfer.py @@ -25,6 +25,7 @@ import queue import threading import time import typing +from typing import Optional from . import progress @@ -186,7 +187,7 @@ class FileTransferer(threading.Thread, metaclass=abc.ABCMeta): if self.done.is_set(): return - def join(self, timeout: float = None) -> None: + def join(self, timeout: Optional[float] = None) -> None: """Wait for the transfer to finish/stop.""" if timeout: diff --git a/blender_asset_tracer/trace/result.py b/blender_asset_tracer/trace/result.py index a8e4093..fcbf2b5 100644 --- a/blender_asset_tracer/trace/result.py +++ b/blender_asset_tracer/trace/result.py @@ -21,6 +21,7 @@ import functools import logging import pathlib import typing +from typing import Optional from blender_asset_tracer import blendfile, bpathlib from blender_asset_tracer.blendfile import dna @@ -57,9 +58,9 @@ class BlockUsage: block: blendfile.BlendFileBlock, asset_path: bpathlib.BlendPath, is_sequence: bool = False, - path_full_field: dna.Field = None, - path_dir_field: dna.Field = None, - path_base_field: dna.Field = None, + path_full_field: Optional[dna.Field] = None, + path_dir_field: Optional[dna.Field] = None, + path_base_field: Optional[dna.Field] = None, block_name: bytes = b"", ) -> None: if block_name: diff --git a/tests/abstract_test.py b/tests/abstract_test.py index b25a555..167c8f9 100644 --- a/tests/abstract_test.py +++ b/tests/abstract_test.py @@ -20,6 +20,7 @@ import logging import pathlib import unittest +from typing import Optional from blender_asset_tracer import blendfile @@ -29,6 +30,9 @@ logging.basicConfig( class AbstractBlendFileTest(unittest.TestCase): + blendfiles: pathlib.Path + bf: Optional[blendfile.BlendFile] + @classmethod def setUpClass(cls): cls.blendfiles = pathlib.Path(__file__).with_name("blendfiles") diff --git a/tests/test_shaman_transfer.py b/tests/test_shaman_transfer.py index f4e5533..0b137f2 100644 --- a/tests/test_shaman_transfer.py +++ b/tests/test_shaman_transfer.py @@ -19,6 +19,7 @@ # (c) 2019, Blender Foundation - Sybren A. Stüvel import pathlib import platform +from typing import Dict import responses @@ -29,6 +30,12 @@ httpmock = responses.RequestsMock() class ShamanTransferTest(AbstractBlendFileTest): + test_file1: pathlib.Path + test_file2: pathlib.Path + expected_checksums: Dict[pathlib.Path, str] + file_sizes: Dict[pathlib.Path, int] + packed_names: Dict[pathlib.Path, str] + @classmethod def setUpClass(cls): super().setUpClass() diff --git a/tests/test_tracer.py b/tests/test_tracer.py index bda1519..20967aa 100644 --- a/tests/test_tracer.py +++ b/tests/test_tracer.py @@ -2,6 +2,7 @@ import collections import logging import sys import typing +from typing import Optional from blender_asset_tracer import trace, blendfile from blender_asset_tracer.blendfile import dna @@ -65,7 +66,7 @@ class AssetHoldingBlocksTest(AbstractTracerTest): class DepsTest(AbstractTracerTest): @staticmethod - def field_name(field: dna.Field) -> typing.Optional[str]: + def field_name(field: Optional[dna.Field]) -> typing.Optional[str]: if field is None: return None return field.name.name_full.decode() @@ -88,18 +89,18 @@ class DepsTest(AbstractTracerTest): exp = expects.get(dep.block_name, None) if isinstance(exp, (set, list)): - self.assertIn(actual, exp, msg="for block %s" % dep.block_name) + self.assertIn(actual, exp, msg="for block %r" % dep.block_name) exp.remove(actual) if not exp: # Don't leave empty sets in expects. del expects[dep.block_name] elif exp is None: self.assertIsNone( - actual, msg="unexpected dependency of block %s" % dep.block_name + actual, msg="unexpected dependency of block %r" % dep.block_name ) del expects[dep.block_name] else: - self.assertEqual(exp, actual, msg="for block %s" % dep.block_name) + self.assertEqual(exp, actual, msg="for block %r" % dep.block_name) del expects[dep.block_name] # All expected uses should have been seen.