497bb7
diff -U3 -r cython-0.29.17.orig/Cython/Compiler/ExprNodes.py cython-0.29.17/Cython/Compiler/ExprNodes.py
497bb7
--- cython-0.29.17.orig/Cython/Compiler/ExprNodes.py	2020-04-26 13:48:48.000000000 +0200
497bb7
+++ cython-0.29.17/Cython/Compiler/ExprNodes.py	2020-05-15 17:44:55.157172257 +0200
497bb7
@@ -2295,8 +2295,10 @@
497bb7
                 setter = 'PyDict_SetItem'
497bb7
                 namespace = Naming.moddict_cname
497bb7
             elif entry.is_pyclass_attr:
497bb7
-                code.globalstate.use_utility_code(UtilityCode.load_cached("SetNameInClass", "ObjectHandling.c"))
497bb7
-                setter = '__Pyx_SetNameInClass'
497bb7
+                # Special-case setting __new__
497bb7
+                n = "SetNewInClass" if self.name == "__new__" else "SetNameInClass"
497bb7
+                code.globalstate.use_utility_code(UtilityCode.load_cached(n, "ObjectHandling.c"))
497bb7
+                setter = '__Pyx_' + n
497bb7
             else:
497bb7
                 assert False, repr(entry)
497bb7
             code.put_error_if_neg(
497bb7
diff -U3 -r cython-0.29.17.orig/Cython/Compiler/Nodes.py cython-0.29.17/Cython/Compiler/Nodes.py
497bb7
--- cython-0.29.17.orig/Cython/Compiler/Nodes.py	2020-04-26 13:48:48.000000000 +0200
497bb7
+++ cython-0.29.17/Cython/Compiler/Nodes.py	2020-05-15 17:44:55.159172253 +0200
497bb7
@@ -2872,7 +2872,6 @@
497bb7
                 func = decorator.decorator
497bb7
                 if func.is_name:
497bb7
                     self.is_classmethod |= func.name == 'classmethod'
497bb7
-                    self.is_staticmethod |= func.name == 'staticmethod'
497bb7
 
497bb7
         if self.is_classmethod and env.lookup_here('classmethod'):
497bb7
             # classmethod() was overridden - not much we can do here ...
497bb7
diff -U3 -r cython-0.29.17.orig/Cython/Utility/ObjectHandling.c cython-0.29.17/Cython/Utility/ObjectHandling.c
497bb7
--- cython-0.29.17.orig/Cython/Utility/ObjectHandling.c	2020-04-26 13:48:48.000000000 +0200
497bb7
+++ cython-0.29.17/Cython/Utility/ObjectHandling.c	2020-05-15 17:44:55.160172251 +0200
497bb7
@@ -1163,6 +1163,30 @@
497bb7
 #define __Pyx_SetNameInClass(ns, name, value)  PyObject_SetItem(ns, name, value)
497bb7
 #endif
497bb7
 
497bb7
+/////////////// SetNewInClass.proto ///////////////
497bb7
+
497bb7
+static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value);
497bb7
+
497bb7
+/////////////// SetNewInClass ///////////////
497bb7
+//@requires: SetNameInClass
497bb7
+
497bb7
+// Special-case setting __new__: if it's a Cython function, wrap it in a
497bb7
+// staticmethod. This is similar to what Python does for a Python function
497bb7
+// called __new__.
497bb7
+static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value) {
497bb7
+#ifdef __Pyx_CyFunction_USED
497bb7
+    int ret;
497bb7
+    if (__Pyx_CyFunction_Check(value)) {
497bb7
+        PyObject *staticnew = PyStaticMethod_New(value);
497bb7
+        if (unlikely(!staticnew)) return -1;
497bb7
+        ret = __Pyx_SetNameInClass(ns, name, staticnew);
497bb7
+        Py_DECREF(staticnew);
497bb7
+        return ret;
497bb7
+    }
497bb7
+#endif
497bb7
+    return __Pyx_SetNameInClass(ns, name, value);
497bb7
+}
497bb7
+
497bb7
 
497bb7
 /////////////// GetModuleGlobalName.proto ///////////////
497bb7
 //@requires: PyDictVersioning
497bb7
Only in cython-0.29.17.orig: cython-0.29.17
497bb7
diff -U3 -r cython-0.29.17.orig/tests/run/cyfunction.pyx cython-0.29.17/tests/run/cyfunction.pyx
497bb7
--- cython-0.29.17.orig/tests/run/cyfunction.pyx	2020-04-26 13:48:48.000000000 +0200
497bb7
+++ cython-0.29.17/tests/run/cyfunction.pyx	2020-05-15 17:44:55.160172251 +0200
497bb7
@@ -376,6 +376,18 @@
497bb7
     def meth(self): pass
497bb7
 
497bb7
 
497bb7
+class TestStaticmethod(object):
497bb7
+    """
497bb7
+    >>> x = TestStaticmethod()
497bb7
+    >>> x.staticmeth(42)
497bb7
+    42
497bb7
+    >>> x.staticmeth.__get__(42)()
497bb7
+    42
497bb7
+    """
497bb7
+    @staticmethod
497bb7
+    def staticmeth(arg): return arg
497bb7
+
497bb7
+
497bb7
 cdef class TestOptimisedBuiltinMethod:
497bb7
     """
497bb7
     >>> obj = TestOptimisedBuiltinMethod()
497bb7
diff -U3 -r cython-0.29.17.orig/tests/run/fused_def.pyx cython-0.29.17/tests/run/fused_def.pyx
497bb7
--- cython-0.29.17.orig/tests/run/fused_def.pyx	2020-04-26 13:48:48.000000000 +0200
497bb7
+++ cython-0.29.17/tests/run/fused_def.pyx	2020-05-15 18:03:39.436752174 +0200
497bb7
@@ -268,14 +268,6 @@
497bb7
 def test_fused_def_super():
497bb7
     """
497bb7
     >>> test_fused_def_super()
497bb7
-    long 10
497bb7
-    long 11
497bb7
-    long 11
497bb7
-    long 12
497bb7
-    short 12
497bb7
-    long 13
497bb7
-    short 13
497bb7
-    long 14
497bb7
     <class 'fused_def.SubClass'> long 14
497bb7
     <class 'fused_def.SubClass'> long 15
497bb7
     <class 'fused_def.SubClass'> long 15
497bb7
@@ -296,11 +288,6 @@
497bb7
     obj = SubClass()
497bb7
     cls = SubClass
497bb7
 
497bb7
-    obj.mystaticmethod(obj, 10)
497bb7
-    cls.mystaticmethod(obj, 11)
497bb7
-    obj.mystaticmethod[cy.short](obj, 12)
497bb7
-    cls.mystaticmethod[cy.short](obj, 13)
497bb7
-
497bb7
     obj.myclassmethod(14)
497bb7
     cls.myclassmethod(15)
497bb7
     obj.myclassmethod[cy.short](16)