Refactor type hints and clean up code#432
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 filesThere was a problem hiding this comment.
(Apologies, I'll look at this hopefully some time soon. I've been busy with something else.)
There was a problem hiding this comment.
I wish for you to have the support you need, health, and happiness.
(Apologies most certainly accepted.)
There was a problem hiding this comment.
isort merged code that may fix the issue PyCQA/isort#2553. I haven't tested it, and they haven't published a new version yet. As they say here in Mexico, "poco a poco."
| Mapping, | ||
| MutableMapping, | ||
| Optional, | ||
| Sequence, |
There was a problem hiding this comment.
Here and in the next import line you can try removing the last trailing comma to see if the formatter will put things on a single line. Always satisfying.
|
|
||
|
|
||
| def _unstructure_data( | ||
| value: bytes | list[Any] | tuple[Any, ...] | Mapping[K, Any] | T, |
There was a problem hiding this comment.
How did you come up with these types?
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.