This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 48cfe284e9d [v3-0-test] Fix mypy not liking `@field.default` -- it 
thinks it is missing a value (#51835) (#54106)
48cfe284e9d is described below

commit 48cfe284e9dd975e77035e7df7f7995c04cf8815
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Aug 5 10:13:00 2025 +0100

    [v3-0-test] Fix mypy not liking `@field.default` -- it thinks it is missing 
a value (#51835) (#54106)
    
    We can fix this with the slightly more verbose `default=Factory(...,
    take_self=True)` style.
    
    (cherry picked from commit fa5c1480c97958f1ca152bff7667bbb39b1f6bbf)
    
    Co-authored-by: Ash Berlin-Taylor <[email protected]>
---
 .../src/airflow/api_fastapi/auth/tokens.py         | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/airflow-core/src/airflow/api_fastapi/auth/tokens.py 
b/airflow-core/src/airflow/api_fastapi/auth/tokens.py
index a1e6729e5ea..ec20771c561 100644
--- a/airflow-core/src/airflow/api_fastapi/auth/tokens.py
+++ b/airflow-core/src/airflow/api_fastapi/auth/tokens.py
@@ -370,6 +370,18 @@ def _load_key_from_configured_file() -> AllowedPrivateKeys 
| None:
         return _pem_to_key(fh.read())
 
 
+def _generate_kid(gen) -> str:
+    if not gen._private_key:
+        return "not-used"
+
+    if kid := _conf_factory("api_auth", "jwt_kid", fallback=None)():
+        return kid
+
+    # Generate it from the thumbprint of the private key
+    info = key_to_jwk_dict(gen._private_key)
+    return info["kid"]
+
+
 @attrs.define(repr=False, kw_only=True)
 class JWTGenerator:
     """Generate JWT tokens."""
@@ -390,7 +402,7 @@ class JWTGenerator:
     )
     """A pre-shared secret key to sign tokens with symmetric encryption"""
 
-    kid: str = attrs.field()
+    kid: str = attrs.field(default=attrs.Factory(_generate_kid, 
takes_self=True))
     valid_for: float
     audience: str
     issuer: str | list[str] | None = attrs.field(
@@ -400,18 +412,6 @@ class JWTGenerator:
         factory=_conf_list_factory("api_auth", "jwt_algorithm", 
first_only=True, fallback="GUESS")
     )
 
-    @kid.default
-    def _generate_kid(self):
-        if not self._private_key:
-            return "not-used"
-
-        if kid := _conf_factory("api_auth", "jwt_kid", fallback=None)():
-            return kid
-
-        # Generate it from the thumbprint of the private key
-        info = key_to_jwk_dict(self._private_key)
-        return info["kid"]
-
     def __attrs_post_init__(self):
         if not (self._private_key is None) ^ (self._secret_key is None):
             raise ValueError("Exactly one of private_key and secret_key must 
be specified")

Reply via email to