|
Zbigniew Jędrzejewski-Szmek |
d4feac |
From f73a97aba7f6a586bf96ad970294a332109ab558 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Date: Sun, 24 Apr 2022 12:54:57 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Subject: [PATCH] py3.11: fix Enum formatting to work with python3.11-a7
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Something strange is happening with .__repr__() access in python3.11:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
>>> mkosi.backend.ManifestFormat.mro()
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
[<enum 'ManifestFormat'>, <class 'mkosi.backend.Parseable'>, <enum 'Enum'>, <class 'object'>]
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
>>> mkosi.backend.ManifestFormat.changelog.__repr__()
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Traceback (most recent call last):
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
File "<stdin>", line 1, in <module>
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
File "/usr/lib64/python3.11/enum.py", line 1194, in __repr__
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
^^^^^^^^^^^^^^^^^^^^
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
File "/home/zbyszek/src/mkosi/mkosi/backend.py", line 95, in __repr__
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
return cast(str, getattr(self, "name"))
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
^^^^^^^^^^^^^^^^^^^^^
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
AttributeError: 'str' object has no attribute 'name'
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Enum somehow subverts normal lookup and makes its own __repr__ function be
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
used, even though Parseable is listed first in MRO. This seems to be related to
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
PEP 663, which was rejected, and the changes reverted for -a4 [1], but then the revert
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
was reverted [2].
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Let's just sidestep MRO with a method redefinition:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
>>> mkosi.backend.ManifestFormat.changelog.__repr__
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
<bound method ManifestFormat.__repr__ of changelog>
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
>>> mkosi.backend.ManifestFormat.changelog.__repr__()
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
'changelog'
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
This should work on all python versions. If python3.11 returns to previous
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
semantics before the final release, we can remove the workaround.
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
[1] commit acf7403f9baea3ae1119fc6b4a3298522188bf96
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Author: Ethan Furman <ethan@stoneleaf.us>
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Date: Sat Jan 15 22:41:43 2022 -0800
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
bpo-40066: [Enum] update str() and format() output (GH-30582)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Undo rejected PEP-663 changes:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
- restore `repr()` to its 3.10 status
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
- restore `str()` to its 3.10 status
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
[2] commit 42a64c03ec5c443f2a5c2ee4284622f5d1f5326c
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Author: Victor Stinner <vstinner@python.org>
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Date: Mon Jan 17 13:58:40 2022 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" (GH-30632)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
This reverts commit acf7403f9baea3ae1119fc6b4a3298522188bf96.
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
---
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
mkosi/backend.py | 8 ++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
1 file changed, 8 insertions(+)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
diff --git a/mkosi/backend.py b/mkosi/backend.py
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
index 78006f392a..3c57ec6295 100644
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
--- a/mkosi/backend.py
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+++ b/mkosi/backend.py
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
@@ -217,11 +217,19 @@ class OutputFormat(Parseable, enum.Enum):
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
def has_fs_compression(self) -> bool:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
return self.is_squashfs() or self.is_btrfs()
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ def __repr__(self) -> str:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ return Parseable.__repr__(self)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ def __str__(self) -> str:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ return Parseable.__str__(self)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
class ManifestFormat(Parseable, enum.Enum):
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
json = "json" # the standard manifest in json format
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
changelog = "changelog" # human-readable text file with package changelogs
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ def __repr__(self) -> str:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ return Parseable.__repr__(self)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ def __str__(self) -> str:
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
+ return Parseable.__str__(self)
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
class PartitionIdentifier(enum.Enum):
|
|
Zbigniew Jędrzejewski-Szmek |
d4feac |
esp = 'esp'
|