Commit 6b9939475e for bind

commit 6b9939475eb30f52ffee06f2b93fe9c90a50f302
Author: Michal Nowak <mnowak@isc.org>
Date:   Fri Oct 9 14:16:30 2026 +0000

    Annotate self-returning methods with typing.Self

    typing.Self is available since Python 3.11, now the minimum for the
    system tests.  Use it for the context managers and for the TcpStatus
    alternative constructors, and annotate the context managers' ignored
    __exit__() arguments as object, as typeshed does.  WatchLog.__enter__()
    was annotated as returning Any, so type checkers could not see what a
    "with ... as watcher" block bound.  With Self they do, and mypy now
    catches wait_keymgr_done() passing a list[str] where the invariant
    list[FlexPattern] is expected; annotate that list.

    Assisted-by: Claude:claude-opus-5-5

diff --git a/bin/tests/system/isctest/kasp.py b/bin/tests/system/isctest/kasp.py
index 68f74297b3..e7929d2e59 100644
--- a/bin/tests/system/isctest/kasp.py
+++ b/bin/tests/system/isctest/kasp.py
@@ -32,6 +32,7 @@ import dns.zone
 from isctest.algorithms import ALL_ALGORITHMS_BY_DST, ECDSAP256SHA256, Algorithm
 from isctest.instance import NamedInstance
 from isctest.run import EnvCmd
+from isctest.text import FlexPattern
 from isctest.zone import FileZoneKey

 import isctest.log
@@ -1721,7 +1722,7 @@ def wait_keymgr_done(server: NamedInstance, zone: str, reconfig: bool = False) -
     """
     Block and wait until the keymgr is done processing zone.
     """
-    messages = []
+    messages: list[FlexPattern] = []
     if reconfig:
         messages.append("received control channel command 'reconfig'")
         messages.append("apply_configuration")
diff --git a/bin/tests/system/isctest/log/watchlog.py b/bin/tests/system/isctest/log/watchlog.py
index 643950b516..efc2e0da50 100644
--- a/bin/tests/system/isctest/log/watchlog.py
+++ b/bin/tests/system/isctest/log/watchlog.py
@@ -10,7 +10,7 @@
 # information regarding copyright ownership.

 from re import Match, Pattern
-from typing import Any, TextIO, TypeAlias, TypeVar
+from typing import Self, TextIO, TypeAlias, TypeVar

 import abc
 import os
@@ -354,7 +354,7 @@ class WatchLog(abc.ABC):

         return matches

-    def __enter__(self) -> Any:
+    def __enter__(self) -> Self:
         self._fd = open(self._path, encoding="utf-8")
         self._seek_on_enter()
         self._reader = LineReader(self._fd)
@@ -371,7 +371,7 @@ class WatchLog(abc.ABC):
         """
         raise NotImplementedError

-    def __exit__(self, *_: Any) -> None:
+    def __exit__(self, *_: object) -> None:
         if not self._wait_function_called:
             raise WatchLogException("wait_for_*() was not called")
         self._reader = None
diff --git a/bin/tests/system/isctest/rndc.py b/bin/tests/system/isctest/rndc.py
index 5632b0007f..e677fc55fc 100644
--- a/bin/tests/system/isctest/rndc.py
+++ b/bin/tests/system/isctest/rndc.py
@@ -13,7 +13,7 @@
 This module implements the RNDC control protocol.
 """

-from typing import Any
+from typing import Any, Self

 import base64
 import hashlib
@@ -104,10 +104,10 @@ class RNDCClient:
             self.socket.close()
             raise

-    def __enter__(self) -> "RNDCClient":
+    def __enter__(self) -> Self:
         return self

-    def __exit__(self, *_: Any) -> None:
+    def __exit__(self, *_: object) -> None:
         self.close()

     def close(self) -> None:
diff --git a/bin/tests/system/tcp/tests_tcp.py b/bin/tests/system/tcp/tests_tcp.py
index f874a806f0..7885cdd8c5 100644
--- a/bin/tests/system/tcp/tests_tcp.py
+++ b/bin/tests/system/tcp/tests_tcp.py
@@ -11,7 +11,7 @@

 from collections.abc import Iterable, Iterator
 from types import TracebackType
-from typing import NamedTuple
+from typing import NamedTuple, Self

 import asyncio
 import contextlib
@@ -68,7 +68,7 @@ class TcpStatus(NamedTuple):
             )

     @classmethod
-    def of(cls, ns: NamedInstance) -> "TcpStatus":
+    def of(cls, ns: NamedInstance) -> Self:
         status = ns.rndc("status").out

         def value(label: str) -> str:
@@ -98,8 +98,8 @@ class TcpStatus(NamedTuple):
         recursive_high_water: int | None = None,
         timeout: int = 2,
         delay: int = 1,
-    ) -> "TcpStatus":
-        status: TcpStatus | None = None
+    ) -> Self:
+        status: Self | None = None

         def check() -> bool:
             nonlocal status
@@ -123,7 +123,7 @@ class TcpConnectionPool:
     def __init__(self) -> None:
         self.connections: list[socket.socket] = []

-    async def __aenter__(self) -> "TcpConnectionPool":
+    async def __aenter__(self) -> Self:
         return self

     async def __aexit__(
diff --git a/pyproject.toml b/pyproject.toml
index 7b7ceee0e8..3550a697e5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -113,6 +113,10 @@ lint.select = [
   "UP017",
   # TimeoutError aliases
   "UP041",
+  # __enter__ and friends return Self
+  "PYI034",
+  # __exit__ star-args are object
+  "PYI036",
   # f-strings
   "UP031",
   "UP032",