Refactor type hints and clean up code#432
Refactor type hints and clean up code#432hunterhogan wants to merge 5 commits intofonttools:mainfrom
Conversation
| import pytest | ||
|
|
||
| import ufoLib2.objects | ||
| import ufoLib2.serde.json # noqa: E402 |
There was a problem hiding this comment.
Don't move this. This test module needs to be skipped if the cattrs library isn't installed, so the import needs to come after the next line.
There was a problem hiding this comment.
To me, the # isort: off syntax looks correct, but the isort CLI moved imports in this file and in test_msgpack.py.
In this other branch, in the first commit, test_json.py is unchanged by all of the commands listed in the commit message.
But isort tests changed the two files in the second commit. The only other # isort: off action comment I found is in test_converters.py. isort did not move that import statement.
If isort were using ast, the moved statements would be parsed to ast.Import objects, while the unmoved statement would be parsed to an ast.ImportFrom object.
On the main branch:
(.venv) C:\clones\ufoLib2>isort --skip-gitignore --check-only --diff src tests
ERROR: C:\clones\ufoLib2\tests\serde\test_json.py Imports are incorrectly sorted and/or formatted.
--- C:\clones\ufoLib2\tests\serde\test_json.py:before 2026-04-14 16:35:42.775384
+++ C:\clones\ufoLib2\tests\serde\test_json.py:after 2026-04-14 16:35:49.397888
@@ -7,11 +7,11 @@
import pytest
import ufoLib2.objects
+import ufoLib2.serde.json # noqa: E402
# isort: off
pytest.importorskip("cattrs")
-import ufoLib2.serde.json # noqa: E402
@pytest.mark.parametrize("have_orjson", [False, True], ids=["no-orjson", "with-orjson"])
ERROR: C:\clones\ufoLib2\tests\serde\test_msgpack.py Imports are incorrectly sorted and/or formatted.
--- C:\clones\ufoLib2\tests\serde\test_msgpack.py:before 2026-04-14 16:35:42.776376
+++ C:\clones\ufoLib2\tests\serde\test_msgpack.py:after 2026-04-14 16:35:49.406060
@@ -1,16 +1,16 @@
from pathlib import Path
+import msgpack # type: ignore # noqa
import pytest
import ufoLib2.objects
+import ufoLib2.serde.msgpack # noqa: E402
# isort: off
pytest.importorskip("cattrs")
pytest.importorskip("msgpack")
-import msgpack # type: ignore # noqa
-import ufoLib2.serde.msgpack # noqa: E402
def test_dumps_loads(ufo_UbuTestData: ufoLib2.objects.Font) -> None:
Skipped 1 files
Update type hints to use
typeinstead ofType, remove unnecessary checks, and fix typos throughout the codebase. Enhance type annotations for better clarity and maintainability. A continuation of #423.