Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Tamir Duberstein <tamird@kernel.org>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Tamir Duberstein <tamird@kernel.org>
Subject: [PATCH ezgb v2 2/3] Enable strict pyright source checks
Date: Fri, 18 Sep 2026 18:03:22 -0400	[thread overview]
Message-ID: <20260918-stronger-type-checking-v2-2-3ddc31ba2616@kernel.org> (raw)
In-Reply-To: <20260918-stronger-type-checking-v2-0-3ddc31ba2616@kernel.org>

Remove the blanket unknown-type and private-usage exemptions now that
JSON and git objects are narrowed before use. Limit the private-usage
exception to tests, which intentionally exercise internal helpers.

Move the shared date parser to module scope so GitBugRepo no longer
calls a private BugReader method, and give dataclass factories explicit
element types.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
Assisted-by: LLM
---
 pyproject.toml       | 13 +++----------
 src/ezgb/__init__.py |  8 +++-----
 src/ezgb/_models.py  |  4 ++--
 src/ezgb/_reader.py  | 40 ++++++++++++++++++++--------------------
 4 files changed, 28 insertions(+), 37 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 3f2ddb9..28289fe 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -61,16 +61,9 @@ quote-style = "single"
 # pyright tries to type-check every package in each one).
 exclude = [".venv", ".venv-*"]
 typeCheckingMode = "strict"
-
-# pygit2 ships no type information, so member/variable/argument types coming
-# out of it resolve to Unknown. Relax the strict "unknown type" reports
-# rather than sprinkling casts across every git-object access site.
-reportUnknownArgumentType = false
-reportUnknownMemberType = false
-reportUnknownVariableType = false
-
-# False positives caused by underscore-prefixed helpers used across modules.
-reportPrivateUsage = false
+executionEnvironments = [
+    { root = "tests", reportPrivateUsage = false },
+]
 
 [tool.ty.rules]
 all = "error"
diff --git a/src/ezgb/__init__.py b/src/ezgb/__init__.py
index eb65cfc..1f7d0ab 100644
--- a/src/ezgb/__init__.py
+++ b/src/ezgb/__init__.py
@@ -23,7 +23,7 @@ from ezgb._models import (
     Status,
     UnsupportedFormatError,
 )
-from ezgb._reader import BugReader
+from ezgb._reader import BugReader, parse_since
 from ezgb._types import JsonValue
 from ezgb._writer import BugWriter
 
@@ -77,9 +77,7 @@ class GitBugRepo:
                 since = since.replace(tzinfo=timezone.utc)
             return int(since.timestamp())
         # str -- delegate to the reader's parser
-        from ezgb._reader import BugReader
-
-        return BugReader._parse_since(since)
+        return parse_since(since)
 
     def list_bugs(
         self,
@@ -207,7 +205,7 @@ class GitBugRepo:
             author_id = author.get('id', '') if isinstance(author, dict) else ''
             raw_labels = raw.get('labels') or []
             if isinstance(raw_labels, list):
-                labels = frozenset(str(lb) for lb in raw_labels)
+                labels: frozenset[str] = frozenset(str(lb) for lb in raw_labels)
             else:
                 labels = frozenset()
             comment_count = raw.get('comments', 0)
diff --git a/src/ezgb/_models.py b/src/ezgb/_models.py
index 72eb759..426895a 100644
--- a/src/ezgb/_models.py
+++ b/src/ezgb/_models.py
@@ -96,7 +96,7 @@ class Comment:
     text: str
     created_at: datetime
     count: int
-    attachment_ids: list[str] = field(default_factory=list)
+    attachment_ids: list[str] = field(default_factory=list[str])
 
 
 @dataclass
@@ -110,7 +110,7 @@ class Bug:
     created_at: datetime
     labels: set[str]
     comments: list[Comment]
-    metadata: dict[str, str] = field(default_factory=dict)
+    metadata: dict[str, str] = field(default_factory=dict[str, str])
 
 
 @dataclass(frozen=True)
diff --git a/src/ezgb/_reader.py b/src/ezgb/_reader.py
index fe918ec..769604d 100644
--- a/src/ezgb/_reader.py
+++ b/src/ezgb/_reader.py
@@ -56,6 +56,26 @@ def _is_dict_values(value: dict[_K, _T], value_ty: type[_U]) -> TypeGuard[dict[_
     return all(isinstance(value, value_ty) for value in value.values())
 
 
+def parse_since(since: str) -> int:
+    """Parse a datetime string to a unix timestamp.
+
+    Accepts ISO-8601 variants and ``YYYYMMDDHHMMSS``.
+    """
+    since = since.strip()
+    for fmt in (
+        '%Y-%m-%d %H:%M:%S',
+        '%Y%m%d%H%M%S',
+        '%Y-%m-%dT%H:%M:%SZ',
+        '%Y-%m-%dT%H:%M:%S',
+    ):
+        try:
+            dt = datetime.strptime(since, fmt).replace(tzinfo=timezone.utc)
+            return int(dt.timestamp())
+        except ValueError:
+            continue
+    raise ValueError('cannot parse since=%s' % since)
+
+
 def _combine_ids(primary: str, secondary: str) -> str:
     """Interleave primary and secondary IDs into a CombinedId.
 
@@ -412,26 +432,6 @@ class BugReader:
         """Convert a unix timestamp to a timezone-aware datetime."""
         return datetime.fromtimestamp(unix_ts, tz=timezone.utc)
 
-    @staticmethod
-    def _parse_since(since: str) -> int:
-        """Parse a datetime string to a unix timestamp.
-
-        Accepts ISO-8601 variants and ``YYYYMMDDHHMMSS``.
-        """
-        since = since.strip()
-        for fmt in (
-            '%Y-%m-%d %H:%M:%S',
-            '%Y%m%d%H%M%S',
-            '%Y-%m-%dT%H:%M:%SZ',
-            '%Y-%m-%dT%H:%M:%S',
-        ):
-            try:
-                dt = datetime.strptime(since, fmt).replace(tzinfo=timezone.utc)
-                return int(dt.timestamp())
-            except ValueError:
-                continue
-        raise ValueError('cannot parse since=%s' % since)
-
     def build_bug(
         self,
         bid: str,

-- 
2.56.0.rc0.692.g34fd115c35.frankengit


  parent reply	other threads:[~2026-09-18 22:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 22:03 [PATCH ezgb v2 0/3] Tighten JSON and source type checks Tamir Duberstein
2026-09-18 22:03 ` [PATCH ezgb v2 1/3] Narrow JSON types and type test doubles Tamir Duberstein
2026-09-18 22:03 ` Tamir Duberstein [this message]
2026-09-18 22:03 ` [PATCH ezgb v2 3/3] Document local CI checks Tamir Duberstein
2026-10-05 10:57 ` [PATCH ezgb v2 0/3] Tighten JSON and source type checks Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918-stronger-type-checking-v2-2-3ddc31ba2616@kernel.org \
    --to=tamird@kernel.org \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox