File: py314-annotations.patch

package info (click to toggle)
python-spdx-tools 0.8.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,084 kB
  • sloc: python: 18,675; xml: 12,553; sh: 46; makefile: 6
file content (39 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From: Maxwell G <maxwell@gtmx.me>
Date: Sun, 13 Jul 2025 15:14:50 -0500
Subject: relationship_writer: properly access __annotations__ dict

As of PEP 749 (Python 3.14), it is no longer possible to access
__annotations__ on class instances. __annotations__ is now a descriptor
that is only defined on `type` and not on `object`. Apparently,
accessing __annotations__ on class instances was never supported in the
first place:

> Second, in previous versions of Python it was possible to access the __annotations__ attribute on instances of user-defined classes with annotations. However, this behavior was undocumented and not supported by inspect.get_annotations(), and it cannot be preserved under the PEP 649 framework without bigger changes, such as a new object.__annotations__ descriptor. This behavior change should be called out in porting guides.

Note that making this code call `dataclasses.fields()` to get a list of
fields is probably a better solution here, but I chose the most minimal
change to get this working with Python 3.14. Feel free to close this and
create a new PR if you prefer a different solution.

Ref: https://peps.python.org/pep-0749/#metaclass-behavior-with-pep-649
Signed-off-by: Maxwell G <maxwell@gtmx.me>

Origin: other, https://github.com/spdx/tools-python/pull/858
Bug: https://github.com/spdx/tools-python/issues/866
Bug-Debian: https://bugs.debian.org/1122265
Last-Update: 2026-01-05
---
 src/spdx_tools/spdx3/writer/console/relationship_writer.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/spdx_tools/spdx3/writer/console/relationship_writer.py b/src/spdx_tools/spdx3/writer/console/relationship_writer.py
index 1a8b16a..26b0203 100644
--- a/src/spdx_tools/spdx3/writer/console/relationship_writer.py
+++ b/src/spdx_tools/spdx3/writer/console/relationship_writer.py
@@ -12,5 +12,5 @@ def write_relationship(relationship: Relationship, text_output: TextIO, heading:
     if heading:
         text_output.write("## Relationship\n")
     write_element_properties(relationship, text_output)
-    for property_name in relationship.__annotations__.keys():
+    for property_name in type(relationship).__annotations__.keys():
         write_value(property_name, getattr(relationship, property_name), text_output)