Skip to content

Commit 23791f1

Browse files
committed
update docs about __getmetaclass__
1 parent f8e84be commit 23791f1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/sage/cpython/cython_metaclass.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ file if you are using one).
1919
2020
In the extension type (a.k.a. ``cdef class``) for which you want to
2121
define a metaclass, define a method ``__getmetaclass__`` with a single
22-
unused argument. This method should return a type to be used as
22+
unused argument, and turn off the Cython directive
23+
``always_allow_keywords``. This method should return a type to be used as
2324
metaclass:
2425
2526
.. code-block:: cython
2627
28+
cimport cython
2729
cimport sage.cpython.cython_metaclass
2830
cdef class MyCustomType():
31+
@cython.always_allow_keywords(False)
2932
def __getmetaclass__(_):
3033
from foo import MyMetaclass
3134
return MyMetaclass
@@ -63,8 +66,10 @@ EXAMPLES::
6366
6467
sage: cython( # needs sage.misc.cython
6568
....: '''
69+
....: cimport cython
6670
....: cimport sage.cpython.cython_metaclass
6771
....: cdef class MyCustomType():
72+
....: @cython.always_allow_keywords(False)
6873
....: def __getmetaclass__(_):
6974
....: class MyMetaclass(type):
7075
....: def __init__(*args):
@@ -101,8 +106,10 @@ returns a non-type::
101106
102107
sage: cython( # needs sage.misc.cython
103108
....: '''
109+
....: cimport cython
104110
....: cimport sage.cpython.cython_metaclass
105111
....: cdef class MyCustomType():
112+
....: @cython.always_allow_keywords(False)
106113
....: def __getmetaclass__(_):
107114
....: return 2
108115
....: ''')

src/sage/misc/inherit_comparison.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ cdef class InheritComparisonMetaclass(type):
5454
sage: # needs sage.misc.cython
5555
sage: cython(
5656
....: '''
57+
....: cimport cython
58+
....:
5759
....: from sage.misc.inherit_comparison cimport InheritComparisonMetaclass
5860
....:
5961
....: cdef class Base():
@@ -66,6 +68,7 @@ cdef class InheritComparisonMetaclass(type):
6668
....: return 1
6769
....:
6870
....: cdef class DerivedWithRichcmp(Base):
71+
....: @cython.always_allow_keywords(False)
6972
....: def __getmetaclass__(_):
7073
....: from sage.misc.inherit_comparison import InheritComparisonMetaclass
7174
....: return InheritComparisonMetaclass

0 commit comments

Comments
 (0)