From 34d242c5a028bebd1ba836f42cc523df362ecab2 Mon Sep 17 00:00:00 2001 From: Myles Penner Date: Mon, 19 Jan 2026 10:31:46 -0800 Subject: [PATCH] Postpone annotation evaluation for Python 3.14 Python 3.14 introspection used by unittest.mock autospec evaluates annotations more eagerly. openstack.resource triggers a TypeError ("classmethod object is not subscriptable") during that evaluation, causing unit tests to fail. Also modernize type hints after enabling future annotations. Closes-bug: 2138664 Change-Id: I350fd3fedc8a048c466771b7c3b44731b8a12a90 Signed-off-by: Myles Penner --- openstack/resource.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openstack/resource.py b/openstack/resource.py index 5ebb16a68..576e3232c 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -32,6 +32,8 @@ converted into this Resource class' appropriate components and types and then returned to the caller. """ +from __future__ import annotations + import builtins import collections import collections.abc @@ -905,7 +907,7 @@ class Resource(dict): return "" @staticmethod - def _get_id(value: ty.Union['Resource', str]) -> str: + def _get_id(value: Resource | str) -> str: """If a value is a Resource, return the canonical ID This will return either the value specified by `id` or @@ -954,7 +956,7 @@ class Resource(dict): cls, obj: dict[str, ty.Union], synchronized: bool = True, - connection: ty.Optional['connection.Connection'] = None, + connection: connection.Connection | None = None, ) -> ty_ext.Self: """Create an instance from a ``utils.Munch`` object.