Skip to content

Commit fe128f6

Browse files
committed
fix: resolve small linting and typing issues
1 parent b200efc commit fe128f6

9 files changed

Lines changed: 23 additions & 18 deletions

File tree

tests/explain/test_cli_yaml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typeid import TypeID
88
from typeid.cli import cli
99

10-
1110
yaml = pytest.importorskip("yaml") # skip if PyYAML not installed
1211

1312

tests/explain/test_registry_yaml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from typeid.explain.registry import load_registry
66

7-
87
yaml = pytest.importorskip("yaml") # skip entire file if PyYAML is not installed
98

109

typeid/cli.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
from pathlib import Path
12
from typing import Optional
23

34
import click
45
from uuid6 import UUID
56

67
from typeid import TypeID, base32, from_uuid, get_prefix_and_suffix
7-
8-
from typeid.explain.engine import explain as explain_engine
98
from typeid.explain.discovery import discover_schema_path
9+
from typeid.explain.engine import explain as explain_engine
1010
from typeid.explain.formatters import format_explanation_json, format_explanation_pretty
1111
from typeid.explain.registry import load_registry, make_lookup
1212

@@ -49,7 +49,7 @@ def decode(encoded: str) -> None:
4949
type=click.Path(exists=True, dir_okay=False, path_type=str),
5050
required=False,
5151
help="Path to TypeID schema file (JSON, or YAML if PyYAML is installed). "
52-
"If omitted, TypeID will try to discover a schema automatically.",
52+
"If omitted, TypeID will try to discover a schema automatically.",
5353
)
5454
@click.option(
5555
"--json",
@@ -98,10 +98,6 @@ def explain(
9898
# we keep CLI robust and simply proceed without schema.
9999

100100
if resolved_path:
101-
result = load_registry(click.Path(resolved_path))
102-
# NOTE: click.Path is not a real filesystem path. Convert to pathlib Path.
103-
# We'll do it safely:
104-
from pathlib import Path
105101
result = load_registry(Path(resolved_path))
106102

107103
if result.registry is not None:

typeid/explain/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
from pathlib import Path
1919
from typing import Optional
2020

21-
from .engine import explain as _explain_engine
22-
from .registry import load_registry, make_lookup
2321
from .discovery import discover_schema_path
22+
from .engine import explain as _explain_engine
2423
from .model import Explanation
24+
from .registry import load_registry, make_lookup
2525

2626
__all__ = [
2727
"explain",

typeid/explain/discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from pathlib import Path
2323
from typing import Iterable, Optional
2424

25-
2625
DEFAULT_CWD_CANDIDATES = (
2726
"typeid.schema.json",
2827
"typeid.schema.yaml",
@@ -39,6 +38,7 @@
3938
@dataclass(frozen=True, slots=True)
4039
class DiscoveryResult:
4140
"""Result of schema discovery."""
41+
4242
path: Optional[Path]
4343
source: str # e.g., "env:TYPEID_SCHEMA", "cwd", "user_config", "none"
4444

@@ -69,7 +69,7 @@ def discover_schema_path(
6969
return DiscoveryResult(path=None, source=f"env:{env_var} (not found)")
7070

7171
# 2) Current working directory
72-
cwd_path = (cwd or Path.cwd())
72+
cwd_path = cwd or Path.cwd()
7373
for name in DEFAULT_CWD_CANDIDATES:
7474
p = cwd_path / name
7575
if p.is_file():
@@ -117,7 +117,7 @@ def iter_default_candidate_paths(*, cwd: Optional[Path] = None) -> Iterable[Path
117117
118118
Useful for debugging or `typeid explain --debug-discovery` style features.
119119
"""
120-
cwd_path = (cwd or Path.cwd())
120+
cwd_path = cwd or Path.cwd()
121121
for name in DEFAULT_CWD_CANDIDATES:
122122
yield cwd_path / name
123123

typeid/explain/engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from typeid import TypeID
2020
from typeid.errors import TypeIDException
2121

22-
from .model import Explanation, ParseError, ParsedTypeID, Provenance, TypeSchema
23-
22+
from .model import Explanation, ParsedTypeID, ParseError, Provenance, TypeSchema
2423

2524
SchemaLookup = Callable[[str], Optional[TypeSchema]]
2625

@@ -183,6 +182,7 @@ def _uuid7_created_at(uuid_obj: Any) -> Optional[datetime]:
183182

184183
class _SafeFormatDict(dict):
185184
"""dict that leaves unknown placeholders intact instead of raising KeyError."""
185+
186186
def __missing__(self, key: str) -> str:
187187
return "{" + key + "}"
188188

typeid/explain/formatters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def format_explanation_json(exp: Explanation, *, indent: int = 2) -> str:
118118

119119
class SafeFormatDict(dict):
120120
"""dict that leaves unknown placeholders intact rather than raising KeyError."""
121+
121122
def __missing__(self, key: str) -> str:
122123
return "{" + key + "}"
123124

typeid/explain/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
class Provenance(str, Enum):
1818
"""Where a piece of information came from."""
19+
1920
DERIVED_FROM_ID = "derived_from_id"
2021
SCHEMA = "schema"
2122
EXTERNAL = "external"
@@ -25,6 +26,7 @@ class Provenance(str, Enum):
2526
@dataclass(frozen=True, slots=True)
2627
class ParseError:
2728
"""Represents a recoverable parse/validation error."""
29+
2830
code: str
2931
message: str
3032

@@ -39,6 +41,7 @@ class ParsedTypeID:
3941
- `suffix` is the encoded UUIDv7 portion (base32 string).
4042
- `uuid` and `created_at` are *derived* from suffix if possible.
4143
"""
44+
4245
raw: str
4346
prefix: Optional[str]
4447
suffix: Optional[str]
@@ -61,6 +64,7 @@ class TypeSchema:
6164
breaking the Python API: we store raw dict and also normalize a few
6265
commonly-used fields for nicer UX.
6366
"""
67+
6468
prefix: str
6569
raw: Dict[str, Any] = field(default_factory=dict)
6670

@@ -87,6 +91,7 @@ class Explanation:
8791
- links: rendered links (from schema templates), safe for display
8892
- provenance: per-field provenance labels for transparency
8993
"""
94+
9095
id: str
9196
valid: bool
9297

typeid/explain/registry.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class SchemaRegistry:
5454
5555
Lookup is by full TypeID prefix (which may contain underscores).
5656
"""
57+
5758
def __init__(self, *, schema_version: int, types: Dict[str, TypeSchema], source_path: Path):
5859
self.schema_version = schema_version
5960
self._types = types
@@ -145,10 +146,12 @@ def make_lookup(registry: Optional[SchemaRegistry]):
145146
lookup = make_lookup(reg)
146147
explanation = explain(id, schema_lookup=lookup)
147148
"""
149+
148150
def _lookup(prefix: str) -> Optional[TypeSchema]:
149151
if registry is None:
150152
return None
151153
return registry.get(prefix)
154+
152155
return _lookup
153156

154157

@@ -183,8 +186,10 @@ def _read_schema_file(path: Path) -> Tuple[Dict[str, Any], str]:
183186
# If extension unknown, try JSON first for convenience.
184187
try:
185188
return json.loads(raw), "json"
186-
except Exception:
187-
raise RuntimeError(f"Unsupported schema file extension: {path.suffix!s} (supported: .json, .yaml, .yml)")
189+
except Exception as e:
190+
raise RuntimeError(
191+
f"Unsupported schema file extension: {path.suffix!s} (supported: .json, .yaml, .yml)"
192+
) from e
188193

189194

190195
def _to_type_schema(prefix: str, spec: Dict[str, Any]) -> TypeSchema:

0 commit comments

Comments
 (0)