From f00a25ef213e51f9e66b2934995050b913a44865 Mon Sep 17 00:00:00 2001 From: Ondrej Mular Date: Thu, 26 Nov 2020 09:40:35 +0100 Subject: [PATCH] Python 3.10 related fix --- ...ype-hints-annotations-in-python-3.10.patch | 52 +++++++++++++++++++ pcs.spec | 9 ++-- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 fix-getting-type-hints-annotations-in-python-3.10.patch diff --git a/fix-getting-type-hints-annotations-in-python-3.10.patch b/fix-getting-type-hints-annotations-in-python-3.10.patch new file mode 100644 index 0000000..173cf28 --- /dev/null +++ b/fix-getting-type-hints-annotations-in-python-3.10.patch @@ -0,0 +1,52 @@ +From 9f7c50b9bfaafd5d8368eeb34014e65655318ac0 Mon Sep 17 00:00:00 2001 +From: Ondrej Mular +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 + diff --git a/pcs.spec b/pcs.spec index 85f9e2c..1f1ce0d 100644 --- a/pcs.spec +++ b/pcs.spec @@ -1,6 +1,6 @@ Name: pcs Version: 0.10.7 -Release: 1%{?dist} +Release: 2%{?dist} # https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses # GPLv2: pcs # MIT: ember, handlebars, jquery, jquery-ui @@ -47,7 +47,7 @@ Source44: https://github.com/konradhalas/dacite/archive/v%{dacite_version}/dacit Source100: https://github.com/idevat/pcs-web-ui/archive/%{ui_commit}/%{ui_src_name}.tar.gz Source101: https://github.com/idevat/pcs-web-ui/releases/download/%{ui_commit}/pcs-web-ui-node-modules-%{ui_commit}.tar.xz -# Patch0: name.patch +Patch0: fix-getting-type-hints-annotations-in-python-3.10.patch # git for patches BuildRequires: git @@ -207,7 +207,7 @@ update_times_patch(){ update_times ${patch_file_name} `diffstat -p1 -l ${patch_file_name}` } -# update_times_patch %%{PATCH0} +update_times_patch %{PATCH0} # prepare dirs/files necessary for building web ui # inside SOURCE100 is only directory %%{ui_src_name} @@ -394,6 +394,9 @@ remove_all_tests %license pyagentx_LICENSE.txt %changelog +* Thu Nov 26 2020 Ondrej Mular - 0.10.7-2 +- Python 3.10 related fix + * Wed Sep 30 2020 Miroslav Lisik - 0.10.7-1 - Rebased to latest upstream sources (see CHANGELOG.md) - Added dependency on python packages pyparsing and dateutil