dev-python/cython: drop unused patch

Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2025-06-09 13:13:36 +01:00
parent 6e0f32af28
commit d8f4a5cd4f

View File

@@ -1,54 +0,0 @@
From a0794ffb47c9f44be94b3cd8fe6c639766cbda26 Mon Sep 17 00:00:00 2001
From: Stefan Behnel <stefan_ml@behnel.de>
Date: Sun, 4 May 2025 21:48:27 +0200
Subject: [PATCH] Prevent infinite loop in type inference when a variable is
named like the type of its value (e.g. list += []).
Closes https://github.com/cython/cython/issues/6835
---
Cython/Compiler/ExprNodes.py | 2 +-
tests/run/type_inference.pyx | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index a0413ab8d62..b02154a0b30 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -2042,7 +2042,7 @@ def infer_type(self, env):
return self.inferred_type
return py_object_type
elif (self.entry.type.is_extension_type or self.entry.type.is_builtin_type) and \
- self.name == self.entry.type.name:
+ not self.is_target and self.name == self.entry.type.name:
# Unfortunately the type attribute of type objects
# is used for the pointer to the type they represent.
return type_type
diff --git a/tests/run/type_inference.pyx b/tests/run/type_inference.pyx
index b746d05d9f3..226455dae0d 100644
--- a/tests/run/type_inference.pyx
+++ b/tests/run/type_inference.pyx
@@ -883,3 +886,24 @@ def test_builtin_max():
a = max(self.a, self.a)
assert typeof(a) == "Python object", typeof(a)
C().get_max()
+
+
+def variable_with_name_of_type():
+ """
+ >>> variable_with_name_of_type()
+ ([], 'abc')
+ """
+ # Names like 'list.append' refer to the type and must be inferred as such,
+ # but a simple variable called 'list' is not the same and used to break type inference.
+ # See https://github.com/cython/cython/issues/6835
+ rest_list = []
+ list = [] # note: same name as type of value
+ list += rest_list
+ assert typeof(list) == 'list object', typeof(list)
+
+ rest_str = "abc"
+ str = ""
+ str += rest_str
+ assert typeof(str) == 'str object', typeof(str)
+
+ return list, str