1- # mypy: disallow-untyped-defs=False, disallow-untyped-calls=False
2-
31# /// script
42# dependencies = ["nox>=2025.02.09"]
53# ///
64
5+ from __future__ import annotations
6+
77import contextlib
88import datetime
99import difflib
1818import time
1919import webbrowser
2020from pathlib import Path
21+ from typing import IO , Generator
2122
2223import nox
2324
3940 ],
4041 default = False ,
4142)
42- def tests (session ) :
43+ def tests (session : nox . Session ) -> None :
4344 coverage = ["python" , "-m" , "coverage" ]
4445
4546 session .install (* nox .project .dependency_groups (PYPROJECT , "test" ))
4647 session .install ("-e." )
4748 env = {} if session .python != "3.14" else {"COVERAGE_CORE" : "sysmon" }
4849
50+ assert session .python is not None
51+ assert not isinstance (session .python , bool )
4952 if "pypy" not in session .python :
5053 session .run (
5154 * coverage ,
@@ -68,7 +71,7 @@ def tests(session):
6871
6972
7073@nox .session (python = "3.9" )
71- def lint (session ) :
74+ def lint (session : nox . Session ) -> None :
7275 # Run the linters (via pre-commit)
7376 session .install ("pre-commit" )
7477 session .run ("pre-commit" , "run" , "--all-files" , * session .posargs )
@@ -80,7 +83,7 @@ def lint(session):
8083
8184
8285@nox .session (python = "3.9" , default = False )
83- def docs (session ) :
86+ def docs (session : nox . Session ) -> None :
8487 shutil .rmtree ("docs/_build" , ignore_errors = True )
8588 session .install ("-r" , "docs/requirements.txt" )
8689 session .install ("-e" , "." )
@@ -106,7 +109,7 @@ def docs(session):
106109
107110
108111@nox .session (default = False )
109- def release (session ) :
112+ def release (session : nox . Session ) -> None :
110113 package_name = "packaging"
111114 version_file = Path (f"src/{ package_name } /__init__.py" )
112115 changelog_file = Path ("CHANGELOG.rst" )
@@ -193,7 +196,7 @@ def update_licenses(session: nox.Session) -> None:
193196# -----------------------------------------------------------------------------
194197# Helpers
195198# -----------------------------------------------------------------------------
196- def _get_version_from_arguments (arguments ) :
199+ def _get_version_from_arguments (arguments : list [ str ]) -> str :
197200 """Checks the arguments passed to `nox -s release`.
198201
199202 Only 1 argument that looks like a version? Return the argument.
@@ -217,7 +220,7 @@ def _get_version_from_arguments(arguments):
217220 return version
218221
219222
220- def _check_working_directory_state (session ) :
223+ def _check_working_directory_state (session : nox . Session ) -> None :
221224 """Check state of the working directory, prior to making the release."""
222225 should_not_exist = ["build/" , "dist/" ]
223226
@@ -226,7 +229,7 @@ def _check_working_directory_state(session):
226229 session .error (f"Remove { ', ' .join (bad_existing_paths )} and try again" )
227230
228231
229- def _check_git_state (session , version_tag ) :
232+ def _check_git_state (session : nox . Session , version_tag : str ) -> None :
230233 """Check state of the git repository, prior to making the release."""
231234 # Ensure the upstream remote pushes to the correct URL.
232235 allowed_upstreams = [
@@ -277,7 +280,7 @@ def _check_git_state(session, version_tag):
277280 session .run ("git" , "tag" , _release_backup_tag , external = True )
278281
279282
280- def _bump (session , * , version , file , kind ) :
283+ def _bump (session : nox . Session , * , version : str , file : Path , kind : str ) -> None :
281284 session .log (f"Bump version to { version !r} " )
282285 contents = file .read_text ()
283286 new_contents = re .sub (
@@ -291,7 +294,9 @@ def _bump(session, *, version, file, kind):
291294
292295
293296@contextlib .contextmanager
294- def _replace_file (original_path ):
297+ def _replace_file (
298+ original_path : Path ,
299+ ) -> Generator [tuple [IO [str ], IO [str ]], None , None ]:
295300 # Create a temporary file.
296301 fh , replacement_path = tempfile .mkstemp ()
297302
@@ -303,7 +308,7 @@ def _replace_file(original_path):
303308 shutil .move (replacement_path , original_path )
304309
305310
306- def _changelog_update_unreleased_title (version , * , file ) :
311+ def _changelog_update_unreleased_title (version : str , * , file : Path ) -> None :
307312 """Update an "*unreleased*" heading to "{version} - {date}" """
308313 yyyy_mm_dd = datetime .datetime .now (tz = datetime .timezone .utc ).strftime ("%Y-%m-%d" )
309314 title = f"{ version } - { yyyy_mm_dd } "
@@ -320,7 +325,7 @@ def _changelog_update_unreleased_title(version, *, file):
320325 replacement .write (line )
321326
322327
323- def _changelog_add_unreleased_title (* , file ) :
328+ def _changelog_add_unreleased_title (* , file : Path ) -> None :
324329 with _replace_file (file ) as (original , replacement ):
325330 # Duplicate first 3 lines from the original file.
326331 for _ in range (3 ):
0 commit comments