@@ -58,7 +58,7 @@ def _is_nested_dict(obj: object) -> TypeGuard[dict[str, dict[str, Any]]]:
5858@functools .cache
5959def get_oldest_supported_python () -> str :
6060 with PYPROJECT_PATH .open ("rb" ) as config :
61- val = tomllib .load (config )["tool" ]["typeshed" ]["oldest_supported_python " ]
61+ val = tomllib .load (config )["tool" ]["typeshed" ]["oldest-supported-python " ]
6262 assert type (val ) is str
6363 return val
6464
@@ -102,16 +102,16 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
102102 data : dict [str , object ] = tomllib .load (f ).get ("tool" , {}).get ("stubtest" , {})
103103
104104 skip : object = data .get ("skip" , False )
105- apt_dependencies : object = data .get ("apt_dependencies " , [])
106- brew_dependencies : object = data .get ("brew_dependencies " , [])
107- choco_dependencies : object = data .get ("choco_dependencies " , [])
105+ apt_dependencies : object = data .get ("apt-dependencies " , [])
106+ brew_dependencies : object = data .get ("brew-dependencies " , [])
107+ choco_dependencies : object = data .get ("choco-dependencies " , [])
108108 extras : object = data .get ("extras" , [])
109- ignore_missing_stub : object = data .get ("ignore_missing_stub " , False )
110- supported_platforms : object = data .get ("supported_platforms " )
111- ci_platforms : object = data .get ("ci_platforms " , DEFAULT_STUBTEST_PLATFORMS )
112- stubtest_dependencies : object = data .get ("stubtest_dependencies " , [])
113- mypy_plugins : object = data .get ("mypy_plugins " , [])
114- mypy_plugins_config : object = data .get ("mypy_plugins_config " , {})
109+ ignore_missing_stub : object = data .get ("ignore-missing-stub " , False )
110+ supported_platforms : object = data .get ("supported-platforms " )
111+ ci_platforms : object = data .get ("ci-platforms " , DEFAULT_STUBTEST_PLATFORMS )
112+ stubtest_dependencies : object = data .get ("stubtest-dependencies " , [])
113+ mypy_plugins : object = data .get ("mypy-plugins " , [])
114+ mypy_plugins_config : object = data .get ("mypy-plugins-config " , {})
115115
116116 assert type (skip ) is bool
117117 assert type (ignore_missing_stub ) is bool
@@ -128,12 +128,12 @@ def read_stubtest_settings(distribution: str) -> StubtestSettings:
128128 assert _is_nested_dict (mypy_plugins_config )
129129
130130 unrecognised_platforms = set (ci_platforms ) - _STUBTEST_PLATFORM_MAPPING .keys ()
131- assert not unrecognised_platforms , f"Unrecognised ci_platforms specified for { distribution !r} : { unrecognised_platforms } "
131+ assert not unrecognised_platforms , f"Unrecognised ci-platforms specified for { distribution !r} : { unrecognised_platforms } "
132132
133133 if supported_platforms is not None :
134134 assert set (ci_platforms ).issubset (
135135 supported_platforms
136- ), f"ci_platforms must be a subset of supported_platforms for { distribution !r} "
136+ ), f"ci-platforms must be a subset of supported-platforms for { distribution !r} "
137137
138138 for platform , dep_key in _STUBTEST_PLATFORM_MAPPING .items ():
139139 if platform not in ci_platforms :
@@ -194,31 +194,31 @@ def is_obsolete(self) -> bool:
194194 {
195195 "version" ,
196196 "dependencies" ,
197- "extra_description " ,
198- "stub_distribution " ,
199- "upstream_repository " ,
200- "obsolete_since " ,
201- "no_longer_updated " ,
197+ "extra-description " ,
198+ "stub-distribution " ,
199+ "upstream-repository " ,
200+ "obsolete-since " ,
201+ "no-longer-updated " ,
202202 "upload" ,
203203 "tool" ,
204- "partial_stub " ,
205- "requires_python " ,
204+ "partial-stub " ,
205+ "requires-python " ,
206206 "mypy-tests" ,
207207 }
208208)
209209_KNOWN_METADATA_TOOL_FIELDS : Final = {
210210 "stubtest" : {
211211 "skip" ,
212- "apt_dependencies " ,
213- "brew_dependencies " ,
214- "choco_dependencies " ,
212+ "apt-dependencies " ,
213+ "brew-dependencies " ,
214+ "choco-dependencies " ,
215215 "extras" ,
216- "ignore_missing_stub " ,
217- "supported_platforms " ,
218- "ci_platforms " ,
219- "stubtest_dependencies " ,
220- "mypy_plugins " ,
221- "mypy_plugins_config " ,
216+ "ignore-missing-stub " ,
217+ "supported-platforms " ,
218+ "ci-platforms " ,
219+ "stubtest-dependencies " ,
220+ "mypy-plugins " ,
221+ "mypy-plugins-config " ,
222222 }
223223}
224224_DIST_NAME_RE : Final = re .compile (r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$" , re .IGNORECASE )
@@ -259,41 +259,41 @@ def read_metadata(distribution: str) -> StubMetadata:
259259 assert isinstance (dependencies_s , list )
260260 dependencies = [parse_dependencies (distribution , dep ) for dep in dependencies_s ]
261261
262- extra_description : object = data .get ("extra_description " ) # pyright: ignore[reportUnknownMemberType]
262+ extra_description : object = data .get ("extra-description " ) # pyright: ignore[reportUnknownMemberType]
263263 assert isinstance (extra_description , (str , type (None )))
264264
265- if "stub_distribution " in data :
266- stub_distribution = data ["stub_distribution " ]
265+ if "stub-distribution " in data :
266+ stub_distribution = data ["stub-distribution " ]
267267 assert isinstance (stub_distribution , str )
268- assert _DIST_NAME_RE .fullmatch (stub_distribution ), f"Invalid 'stub_distribution ' value for { distribution !r} "
268+ assert _DIST_NAME_RE .fullmatch (stub_distribution ), f"Invalid 'stub-distribution ' value for { distribution !r} "
269269 else :
270270 stub_distribution = f"types-{ distribution } "
271271
272- upstream_repository : object = data .get ("upstream_repository " ) # pyright: ignore[reportUnknownMemberType]
272+ upstream_repository : object = data .get ("upstream-repository " ) # pyright: ignore[reportUnknownMemberType]
273273 assert isinstance (upstream_repository , (str , type (None )))
274274 if isinstance (upstream_repository , str ):
275275 parsed_url = urllib .parse .urlsplit (upstream_repository )
276- assert parsed_url .scheme == "https" , f"{ distribution } : URLs in the upstream_repository field should use https"
276+ assert parsed_url .scheme == "https" , f"{ distribution } : URLs in the upstream-repository field should use https"
277277 no_www_please = (
278- f"{ distribution } : `World Wide Web` subdomain (`www.`) should be removed from URLs in the upstream_repository field"
278+ f"{ distribution } : `World Wide Web` subdomain (`www.`) should be removed from URLs in the upstream-repository field"
279279 )
280280 assert not parsed_url .netloc .startswith ("www." ), no_www_please
281281 no_query_params_please = (
282- f"{ distribution } : Query params (`?`) should be removed from URLs in the upstream_repository field"
282+ f"{ distribution } : Query params (`?`) should be removed from URLs in the upstream-repository field"
283283 )
284284 assert parsed_url .hostname in _QUERY_URL_ALLOWLIST or (not parsed_url .query ), no_query_params_please
285- no_fragments_please = f"{ distribution } : Fragments (`#`) should be removed from URLs in the upstream_repository field"
285+ no_fragments_please = f"{ distribution } : Fragments (`#`) should be removed from URLs in the upstream-repository field"
286286 assert not parsed_url .fragment , no_fragments_please
287287 if parsed_url .netloc == "github.com" :
288288 cleaned_url_path = parsed_url .path .strip ("/" )
289289 num_url_path_parts = len (Path (cleaned_url_path ).parts )
290290 bad_github_url_msg = (
291- f"Invalid upstream_repository for { distribution !r} : "
291+ f"Invalid upstream-repository for { distribution !r} : "
292292 "URLs for GitHub repositories always have two parts in their paths"
293293 )
294294 assert num_url_path_parts == 2 , bad_github_url_msg
295295
296- obsolete_since : object = data .get ("obsolete_since " ) # pyright: ignore[reportUnknownMemberType]
296+ obsolete_since : object = data .get ("obsolete-since " ) # pyright: ignore[reportUnknownMemberType]
297297 assert isinstance (obsolete_since , (String , type (None )))
298298 if obsolete_since :
299299 comment = obsolete_since .trivia .comment
@@ -302,26 +302,26 @@ def read_metadata(distribution: str) -> StubMetadata:
302302 obsolete = ObsoleteMetadata (since_version = obsolete_since , since_date = since_date )
303303 else :
304304 obsolete = None
305- no_longer_updated : object = data .get ("no_longer_updated " , False ) # pyright: ignore[reportUnknownMemberType]
305+ no_longer_updated : object = data .get ("no-longer-updated " , False ) # pyright: ignore[reportUnknownMemberType]
306306 assert type (no_longer_updated ) is bool
307307 uploaded_to_pypi : object = data .get ("upload" , True ) # pyright: ignore[reportUnknownMemberType]
308308 assert type (uploaded_to_pypi ) is bool
309- partial_stub : object = data .get ("partial_stub " , True ) # pyright: ignore[reportUnknownMemberType]
309+ partial_stub : object = data .get ("partial-stub " , True ) # pyright: ignore[reportUnknownMemberType]
310310 assert type (partial_stub ) is bool
311- requires_python_str : object = data .get ("requires_python " ) # pyright: ignore[reportUnknownMemberType]
311+ requires_python_str : object = data .get ("requires-python " ) # pyright: ignore[reportUnknownMemberType]
312312 oldest_supported_python = get_oldest_supported_python ()
313313 oldest_supported_python_specifier = Specifier (f">={ oldest_supported_python } " )
314314 if requires_python_str is None :
315315 requires_python = oldest_supported_python_specifier
316316 else :
317317 assert isinstance (requires_python_str , str )
318318 requires_python = Specifier (requires_python_str )
319- assert requires_python != oldest_supported_python_specifier , f'requires_python ="{ requires_python } " is redundant'
319+ assert requires_python != oldest_supported_python_specifier , f'requires-python ="{ requires_python } " is redundant'
320320 # Check minimum Python version is not less than the oldest version of Python supported by typeshed
321321 assert oldest_supported_python_specifier .contains (
322322 requires_python .version
323- ), f"'requires_python ' contains versions lower than typeshed's oldest supported Python ({ oldest_supported_python } )"
324- assert requires_python .operator == ">=" , "'requires_python ' should be a minimum version specifier, use '>=3.x'"
323+ ), f"'requires-python ' contains versions lower than typeshed's oldest supported Python ({ oldest_supported_python } )"
324+ assert requires_python .operator == ">=" , "'requires-python ' should be a minimum version specifier, use '>=3.x'"
325325
326326 empty_tools : dict [object , object ] = {}
327327 tools_settings : object = data .get ("tool" , empty_tools ) # pyright: ignore[reportUnknownMemberType]
@@ -361,6 +361,9 @@ def update_metadata(distribution: str, **new_values: object) -> tomlkit.TOMLDocu
361361 except FileNotFoundError :
362362 raise NoSuchStubError (f"Typeshed has no stubs for { distribution !r} !" ) from None
363363 data .update (new_values ) # pyright: ignore[reportUnknownMemberType] # tomlkit.TOMLDocument.update is partially typed
364+ for key in list (data .keys ()):
365+ new_key = key .replace ("_" , "-" ) # pyright: ignore[reportUnknownMemberType] # tomlkit.TOMLDocument.keys is partially typed
366+ data [new_key ] = data .pop (key ) # pyright: ignore[reportUnknownMemberType] # tomlkit.TOMLDocument.pop is partially typed
364367 with path .open ("w" , encoding = "UTF-8" ) as file :
365368 tomlkit .dump (data , file ) # pyright: ignore[reportUnknownMemberType] # tomlkit.dump has partially unknown Mapping type
366369 return data
0 commit comments