Skip to content

Commit 58a7760

Browse files
fix(oauth): narrow exp_time before subtraction (mypy 1.14 + pyjwt 2.13)
Previous fix wrapped exp_time in bool() to satisfy mypy's [return-value] rule. That didn't narrow the type, so mypy then flagged the `(exp_time - buffer_time)` expression with `[operator]` "Unsupported operand types for - ('None' and 'int')" — the short-circuit at runtime is correct, but mypy can't track narrowing through a bool() call. Replace with explicit `if exp_time is None: return False`. Same runtime semantics (None and falsy exp_time both produce False), cleaner reading, and mypy narrows the rest of the function to int after the guard. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent ac3c86f commit 58a7760

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/databricks/sql/auth/oauth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ def is_expired(self) -> bool:
4343
self.access_token, options={"verify_signature": False}
4444
)
4545
exp_time = decoded_token.get("exp")
46+
if exp_time is None:
47+
return False
4648
current_time = time.time()
4749
buffer_time = 30 # 30 seconds buffer
48-
return bool(exp_time) and (exp_time - buffer_time) <= current_time
50+
return (exp_time - buffer_time) <= current_time
4951
except Exception as e:
5052
logger.error("Failed to decode token: %s", e)
5153
raise e

0 commit comments

Comments
 (0)