Skip to content

Refactor type hints and clean up code#432

Open
hunterhogan wants to merge 5 commits intofonttools:mainfrom
hunterhogan:typing
Open

Refactor type hints and clean up code#432
hunterhogan wants to merge 5 commits intofonttools:mainfrom
hunterhogan:typing

Conversation

@hunterhogan
Copy link
Copy Markdown
Contributor

@hunterhogan hunterhogan commented Apr 11, 2026

Update type hints to use type instead of Type, remove unnecessary checks, and fix typos throughout the codebase. Enhance type annotations for better clarity and maintainability. A continuation of #423.

Comment thread tests/serde/test_json.py Outdated
import pytest

import ufoLib2.objects
import ufoLib2.serde.json # noqa: E402
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants