From 5e1ee975c94287a984bc231fe82d02d8153c8d7e Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 27 May 2025 11:09:37 +0200 Subject: [PATCH] Fix quirk of enum values in Python After the Cython 3 change, the types of enum members such as spacy.parts_of_speech.NOUN became 'flag', rather than simple 'int'. This change mostly doesn't matter because the flag type does duck-type like an int -- it compares, additions, prints etc the same. However, it doesn't repr the same and if you do an isinstance check it will fail. It's therefore better to just make them ints like they were before. --- spacy/attrs.pyx | 3 +++ spacy/parts_of_speech.pyx | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spacy/attrs.pyx b/spacy/attrs.pyx index 363dd094d..50b868bc4 100644 --- a/spacy/attrs.pyx +++ b/spacy/attrs.pyx @@ -91,6 +91,9 @@ IDS = { "MORPH": MORPH, "IDX": IDX, } +# Make these ints in Python, so that we don't get this unexpected 'flag' type +# This will match the behaviour before Cython 3 +IDS = {name: int(value) for name, value in IDS.items()} # ATTR IDs, in order of the symbol diff --git a/spacy/parts_of_speech.pyx b/spacy/parts_of_speech.pyx index 1e643c099..9e539c16c 100644 --- a/spacy/parts_of_speech.pyx +++ b/spacy/parts_of_speech.pyx @@ -23,7 +23,9 @@ IDS = { "SPACE": SPACE } - +# Make these ints in Python, so that we don't get this unexpected 'flag' type +# This will match the behaviour before Cython 3 +IDS = {name: int(value) for name, value in IDS.items()} NAMES = {value: key for key, value in IDS.items()} # As of Cython 3.1, the global Python namespace no longer has the enum