1313from __future__ import annotations
1414
1515import difflib
16- import email .message
16+ import email .parser
17+ import email .policy
1718import functools
1819import json
1920import os
@@ -238,7 +239,9 @@ def tests(session: nox.Session, backend: str, vcs: bool) -> None:
238239 "-c" ,
239240 f'import importlib.metadata as m; print(m.version("{ name } "))' ,
240241 silent = True ,
241- ).strip ()
242+ )
243+ assert version
244+ version = version .strip ()
242245 expected_version = get_expected_version (backend , vcs )
243246 assert version == expected_version , f"{ version = } != { expected_version = } "
244247
@@ -292,7 +295,9 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
292295 (metadata_path ,) = (
293296 n for n in names if n .endswith ("PKG-INFO" ) and "egg-info" not in n
294297 )
295- with tf .extractfile (metadata_path ) as mfile :
298+ efile = tf .extractfile (metadata_path )
299+ assert efile
300+ with efile as mfile :
296301 info = mfile .read ().decode ("utf-8" )
297302 if "License-Expression: BSD-3-Clause" not in info :
298303 msg = "License expression not found in METADATA"
@@ -307,7 +312,11 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
307312 metadata_path = next (iter (n for n in names if n .endswith ("METADATA" )))
308313 with zf .open (metadata_path ) as mfile :
309314 txt = mfile .read ()
310- license_fields = email .message .EmailMessage (txt ).get_all ("License" , [])
315+ license_fields = (
316+ email .parser .BytesParser (policy = email .policy .default )
317+ .parsebytes (txt )
318+ .get_all ("License" , [])
319+ )
311320 if license_fields :
312321 msg = f"Should not have anything in the License slot, got { license_fields } "
313322 session .error (msg )
@@ -408,14 +417,16 @@ def pc_bump(session: nox.Session) -> None:
408417
409418 for proj , (old_version , space ) in old_versions .items ():
410419 if proj not in versions :
411- versions [ proj ] = session .run (
420+ versions_proj = session .run (
412421 "lastversion" ,
413422 "--at=github" ,
414423 "--format=tag" ,
415424 "--exclude=~alpha|beta|rc" ,
416425 proj ,
417426 silent = True ,
418- ).strip ()
427+ )
428+ assert versions_proj
429+ versions [proj ] = versions_proj .strip ()
419430 new_version = versions [proj ]
420431
421432 after = PC_REPL_LINE .format (proj , new_version , space , '"' )
@@ -454,7 +465,7 @@ def get_latest_version_tag(repo: str, old_version: str) -> dict[str, Any] | None
454465 and x ["name" ].startswith ("v" ) == old_version .startswith ("v" )
455466 ]
456467 if tags :
457- return tags [0 ]
468+ return tags [0 ] # type: ignore[no-any-return]
458469 return None
459470
460471
0 commit comments