class-static-method-workaround.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. diff -U3 -r cython-0.29.17.orig/Cython/Compiler/ExprNodes.py cython-0.29.17/Cython/Compiler/ExprNodes.py
  2. --- cython-0.29.17.orig/Cython/Compiler/ExprNodes.py 2020-04-26 13:48:48.000000000 +0200
  3. +++ cython-0.29.17/Cython/Compiler/ExprNodes.py 2020-05-15 17:44:55.157172257 +0200
  4. @@ -2295,8 +2295,10 @@
  5. setter = 'PyDict_SetItem'
  6. namespace = Naming.moddict_cname
  7. elif entry.is_pyclass_attr:
  8. - code.globalstate.use_utility_code(UtilityCode.load_cached("SetNameInClass", "ObjectHandling.c"))
  9. - setter = '__Pyx_SetNameInClass'
  10. + # Special-case setting __new__
  11. + n = "SetNewInClass" if self.name == "__new__" else "SetNameInClass"
  12. + code.globalstate.use_utility_code(UtilityCode.load_cached(n, "ObjectHandling.c"))
  13. + setter = '__Pyx_' + n
  14. else:
  15. assert False, repr(entry)
  16. code.put_error_if_neg(
  17. diff -U3 -r cython-0.29.17.orig/Cython/Compiler/Nodes.py cython-0.29.17/Cython/Compiler/Nodes.py
  18. --- cython-0.29.17.orig/Cython/Compiler/Nodes.py 2020-04-26 13:48:48.000000000 +0200
  19. +++ cython-0.29.17/Cython/Compiler/Nodes.py 2020-05-15 17:44:55.159172253 +0200
  20. @@ -2872,7 +2872,6 @@
  21. func = decorator.decorator
  22. if func.is_name:
  23. self.is_classmethod |= func.name == 'classmethod'
  24. - self.is_staticmethod |= func.name == 'staticmethod'
  25. if self.is_classmethod and env.lookup_here('classmethod'):
  26. # classmethod() was overridden - not much we can do here ...
  27. diff -U3 -r cython-0.29.17.orig/Cython/Utility/ObjectHandling.c cython-0.29.17/Cython/Utility/ObjectHandling.c
  28. --- cython-0.29.17.orig/Cython/Utility/ObjectHandling.c 2020-04-26 13:48:48.000000000 +0200
  29. +++ cython-0.29.17/Cython/Utility/ObjectHandling.c 2020-05-15 17:44:55.160172251 +0200
  30. @@ -1163,6 +1163,30 @@
  31. #define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value)
  32. #endif
  33. +/////////////// SetNewInClass.proto ///////////////
  34. +
  35. +static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value);
  36. +
  37. +/////////////// SetNewInClass ///////////////
  38. +//@requires: SetNameInClass
  39. +
  40. +// Special-case setting __new__: if it's a Cython function, wrap it in a
  41. +// staticmethod. This is similar to what Python does for a Python function
  42. +// called __new__.
  43. +static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value) {
  44. +#ifdef __Pyx_CyFunction_USED
  45. + int ret;
  46. + if (__Pyx_CyFunction_Check(value)) {
  47. + PyObject *staticnew = PyStaticMethod_New(value);
  48. + if (unlikely(!staticnew)) return -1;
  49. + ret = __Pyx_SetNameInClass(ns, name, staticnew);
  50. + Py_DECREF(staticnew);
  51. + return ret;
  52. + }
  53. +#endif
  54. + return __Pyx_SetNameInClass(ns, name, value);
  55. +}
  56. +
  57. /////////////// GetModuleGlobalName.proto ///////////////
  58. //@requires: PyDictVersioning
  59. Only in cython-0.29.17.orig: cython-0.29.17
  60. diff -U3 -r cython-0.29.17.orig/tests/run/cyfunction.pyx cython-0.29.17/tests/run/cyfunction.pyx
  61. --- cython-0.29.17.orig/tests/run/cyfunction.pyx 2020-04-26 13:48:48.000000000 +0200
  62. +++ cython-0.29.17/tests/run/cyfunction.pyx 2020-05-15 17:44:55.160172251 +0200
  63. @@ -376,6 +376,18 @@
  64. def meth(self): pass
  65. +class TestStaticmethod(object):
  66. + """
  67. + >>> x = TestStaticmethod()
  68. + >>> x.staticmeth(42)
  69. + 42
  70. + >>> x.staticmeth.__get__(42)()
  71. + 42
  72. + """
  73. + @staticmethod
  74. + def staticmeth(arg): return arg
  75. +
  76. +
  77. cdef class TestOptimisedBuiltinMethod:
  78. """
  79. >>> obj = TestOptimisedBuiltinMethod()
  80. diff -U3 -r cython-0.29.17.orig/tests/run/fused_def.pyx cython-0.29.17/tests/run/fused_def.pyx
  81. --- cython-0.29.17.orig/tests/run/fused_def.pyx 2020-04-26 13:48:48.000000000 +0200
  82. +++ cython-0.29.17/tests/run/fused_def.pyx 2020-05-15 18:03:39.436752174 +0200
  83. @@ -268,14 +268,6 @@
  84. def test_fused_def_super():
  85. """
  86. >>> test_fused_def_super()
  87. - long 10
  88. - long 11
  89. - long 11
  90. - long 12
  91. - short 12
  92. - long 13
  93. - short 13
  94. - long 14
  95. <class 'fused_def.SubClass'> long 14
  96. <class 'fused_def.SubClass'> long 15
  97. <class 'fused_def.SubClass'> long 15
  98. @@ -296,11 +288,6 @@
  99. obj = SubClass()
  100. cls = SubClass
  101. - obj.mystaticmethod(obj, 10)
  102. - cls.mystaticmethod(obj, 11)
  103. - obj.mystaticmethod[cy.short](obj, 12)
  104. - cls.mystaticmethod[cy.short](obj, 13)
  105. -
  106. obj.myclassmethod(14)
  107. cls.myclassmethod(15)
  108. obj.myclassmethod[cy.short](16)