pcs/fix-getting-type-hints-annotations-in-python-3.10.patch
DistroBaker 60f139c3bb Merged update from upstream sources
This is an automated DistroBaker update from upstream sources.
If you do not know what this is about or would like to opt out,
contact the OSCI team.

Source: https://src.fedoraproject.org/rpms/pcs.git#f00a25ef213e51f9e66b2934995050b913a44865
2020-11-26 11:32:54 +00:00

53 lines
1.9 KiB
Diff

From 9f7c50b9bfaafd5d8368eeb34014e65655318ac0 Mon Sep 17 00:00:00 2001
From: Ondrej Mular <omular@redhat.com>
Date: Wed, 25 Nov 2020 10:16:26 +0100
Subject: [PATCH] fix getting type hints annotations in python 3.10
In Python 3.10 a postponed evaluation of type hint annotations [1] will
be a default [2]. To access annotated types as objects instead of
strings, we need to use function `typing.get_type_hints(...)`
[1]: https://www.python.org/dev/peps/pep-0563/
[2]: https://docs.python.org/3.10/whatsnew/3.10.html#pep-563-postponed-evaluation-of-annotations-becomes-default
---
pcs/cli/reports/messages.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/pcs/cli/reports/messages.py b/pcs/cli/reports/messages.py
index ecf74561..7582aec0 100644
--- a/pcs/cli/reports/messages.py
+++ b/pcs/cli/reports/messages.py
@@ -1,4 +1,5 @@
from typing import (
+ get_type_hints,
Any,
Dict,
Mapping,
@@ -44,7 +45,7 @@ class CliReportMessageCustom(CliReportMessage):
def __init__(self, dto_obj: dto.ReportItemMessageDto) -> None:
super().__init__(dto_obj)
- self._obj = self.__class__.__annotations__.get("_obj")( # type: ignore
+ self._obj = get_type_hints(self.__class__).get("_obj")( # type: ignore
**dto_obj.payload
)
@@ -446,9 +447,11 @@ def _create_report_msg_map() -> Dict[str, type]:
result: Dict[str, type] = {}
for report_msg_cls in get_all_subclasses(CliReportMessageCustom):
# pylint: disable=protected-access
- code = report_msg_cls.__annotations__.get(
- "_obj", item.ReportItemMessage
- )._code
+ code = (
+ get_type_hints(report_msg_cls)
+ .get("_obj", item.ReportItemMessage)
+ ._code
+ )
if code:
if code in result:
raise AssertionError()
--
2.27.0