Refactor type hints and clean up code#432
Conversation
… is already "type[Transform]"
There was a problem hiding this comment.
Override the Black profile magic trailing comma for short lines in import statements with split_on_trailing_comma = false.
If you want to disable the magic trailing comma in Black, so all short lines, not just import statements, would be condensed, add skip-magic-trailing-comma = true to pyproject.toml.
|
I created a scaffold for a recursive I had to temporarily code the scaffold in my idiosyncratic style so that I could "see" the flow. I created 3 Note that PlistScalarBytesBytes: TypeAlias = bool | bytes | datetime | float | int | str
PlistContainerBytes: TypeAlias = (Mapping[str, PlistScalarBytes] | list[PlistScalarBytes] | tuple[PlistScalarBytes, ...])
PlistEncodableBytes: TypeAlias = (Mapping[str, PlistContainerBytes] | list[PlistContainerBytes] | tuple[PlistContainerBytes, ...])At any rate, if you can apply the concepts to class |
|
There's only a 0.001% chance you want this, but... "形": {
"prefix": "xing",
"body": "形",
"description": "形 (xíng): type parameter"
},identifiers.code-snippets.json Oh, crap. I just realized the character will probably break your monospacing. Sorry. This is what I use. https://github.com/hunterhogan/Integrated_code_fire_font |
|
I'll need some time to look into recursive types. What is your intention here? |
I observed this commented-out code. ufoLib2/src/ufoLib2/objects/lib.py Lines 13 to 23 in b787151 I formed the belief that it was indicative of the types, containers, and nesting in unstructure. Furthermore, I formed the beliefs that it would be useful in structure and that someone wanted a recursive type in that module. So, I created a variety of extremely modular, extensible components. Then I implemented overloads and annotations on unstructure that do not trigger type-checker diagnostics to demonstrate that it is syntactically possible to implement recursive types with the components I created. Someone lamented
I hope the components will help address that comment. I guess I am saying: I can't see the "big picture," so here are a bunch of options. Let's work together to select a good system and fine-tune it. |
|
Okay, I remember writing this. It seems that mypy now supports recursive types, this works: from __future__ import annotations
from collections.abc import Mapping, Sequence
from datetime import datetime
from typing import TypeAlias
PlistEncodable: TypeAlias = (
bool
| bytes
| datetime
| float
| int
| str
| Mapping[str, "PlistEncodable"]
| Sequence["PlistEncodable"]
)
def hello(a: PlistEncodable) -> None:
pass
hello(True)
hello(b"abc")
hello(datetime(2026, 1, 1))
hello(1.234)
hello(9)
hello("test")
hello([True, b"abc", datetime(2026, 1, 1), 1.234, 9, "test"])
hello(
{
"key": False,
"hello": b"world",
"nested": [
True,
b"abc",
datetime(2026, 1, 1),
1.234,
9,
"test",
{"abc": {"deeper": True}},
],
}
)I'm using Can you please retry with this definition? Having one type is easier. |
|
Excellent, I moved the module in the right direction. Now, I need your help with some nitty-gritty details and with the complex interaction between Two tests are failing--and they fail in the same way. Failing test: bad. Failing on a highly specific super-nested I have Rumsfeldian ignorance about many of the remaining issues: for me, these are unknown unknowns. The comments I wrote highlight the barriers caused by my ignorance.
|
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.