11"""Configuration for proselint."""
22
33import json
4+ from collections .abc import Hashable
45from importlib .resources import files
56from pathlib import Path
6- from typing import TypedDict
7+ from typing import TypedDict , TypeVar , cast
78from warnings import showwarning as warn
89
910from proselint import config
@@ -23,14 +24,22 @@ class Config(TypedDict):
2324 checks : dict [str , bool ]
2425
2526
26- DEFAULT : Config = json .loads ((files (config ) / "default.json" ).read_text ())
27+ DEFAULT = cast (
28+ "Config" ,
29+ json .loads ((files (config ) / "default.json" ).read_text ())
30+ )
2731
32+ KT_co = TypeVar ("KT_co" , bound = Hashable , covariant = True )
33+ KV_co = TypeVar ("KV_co" , covariant = True )
2834
29- def _deepmerge_dicts (base : dict , overrides : dict ) -> dict :
35+
36+ def _deepmerge_dicts (
37+ base : dict [KT_co , KV_co ], overrides : dict [KT_co , KV_co ]
38+ ) -> dict [KT_co , KV_co ]:
3039 # fmt: off
3140 return base | overrides | {
3241 key : (
33- _deepmerge_dicts (b_value , o_value )
42+ _deepmerge_dicts (b_value , o_value ) # pyright: ignore[reportUnknownArgumentType]
3443 if isinstance (b_value := base [key ], dict )
3544 else o_value
3645 )
@@ -50,9 +59,9 @@ def load_from(config_path: Path | None = None) -> Config:
5059
5160 for path in config_paths :
5261 if path .is_file ():
53- result : Config = _deepmerge_dicts (
54- result ,
55- json .loads (path .read_text ()),
62+ result = _deepmerge_dicts (
63+ dict ( result ) ,
64+ json .loads (path .read_text ()), # pyright: ignore[reportAny]
5665 )
5766 if path .suffix == ".json" and (old := path .with_suffix ("" )).is_file ():
5867 warn (
@@ -62,4 +71,4 @@ def load_from(config_path: Path | None = None) -> Config:
6271 0 ,
6372 )
6473
65- return result
74+ return cast ( "Config" , result )
0 commit comments