Skip to content

Set cython directive binding=True #40341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux-incremental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
from_docker_target: "with-targets"
from_docker_tag: "dev"
docker_targets: "with-targets"
targets: "${{needs.changed_files.outputs.build_targets}} ci-build-with-fallback doc-html ptest-nodoc"
targets: "${{needs.changed_files.outputs.build_targets}} ci-build-with-fallback ptest-nodoc"
tox_system_factors: >-
["ubuntu-focal",
"ubuntu-jammy",
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:

env:
TARGETS_PRE: all-sage-local
TARGETS: build doc-html
TARGETS: build
TARGETS_OPTIONAL: ptest

permissions:
Expand All @@ -41,7 +41,7 @@ jobs:
docker_targets: "with-system-packages configured with-targets-pre with-targets with-targets-optional"
# FIXME: duplicated from env.TARGETS
targets_pre: all-sage-local
targets: build doc-html
targets: build
targets_optional: ptest
tox_system_factors: >-
["ubuntu-jammy"]
Expand All @@ -56,7 +56,7 @@ jobs:
# Build from scratch
docker_targets: "with-system-packages configured with-targets-pre with-targets with-targets-optional"
targets_pre: all-sage-local
targets: build doc-html
targets: build
targets_optional: ptest
tox_packages_factors: >-
["standard"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on:

env:
TARGETS_PRE: all-sage-local
TARGETS: build doc-html
TARGETS: build
TARGETS_OPTIONAL: ptest

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
case "${{ inputs.stage }}" in
1) export TARGETS_PRE="all-sage-local" TARGETS="all-sage-local" TARGETS_OPTIONAL="build/make/Makefile"
;;
2) export TARGETS_PRE="all-sage-local" TARGETS="build doc-html" TARGETS_OPTIONAL="ptest"
2) export TARGETS_PRE="all-sage-local" TARGETS="build" TARGETS_OPTIONAL="ptest"
;;
2-optional*) export TARGETS_PRE="build/make/Makefile" TARGETS="build/make/Makefile"
targets_pattern="${{ inputs.stage }}"
Expand Down
2 changes: 1 addition & 1 deletion build/pkgs/sagemath_doc_html/type
Original file line number Diff line number Diff line change
@@ -1 +1 @@
standard
optional
2 changes: 1 addition & 1 deletion src/doc/en/prep/Programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ It is very important to keep in the parentheses.
::

sage: A.det # Won't work
<built-in method det of sage.matrix.matrix_integer_dense.Matrix_integer_dense object at ...>
<bound method Matrix.det of ...>

This is so useful because we can use the 'tab' key, remember!

Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/prep/Symbolics-and-Basic-Plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ This is a good place for a few reminders of basic help.
::

sage: z.simplify
<built-in method simplify of sage.symbolic.expression.Expression object at ...>
<bound method Expression.simplify of -((x + 1)*sqrt(x - 1) - (x - 1)^(3/2))/sqrt((x + 1)*(x - 1))>

Finally, recall that you can get nicely typeset versions of the output
in several ways.
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ add_project_arguments('-I', meson.current_build_dir(), language: 'cython')
# Add global compiler flags
add_project_arguments('-X auto_pickle=False', language: 'cython')
add_project_arguments('-X autotestdict=False', language: 'cython')
add_project_arguments('-X binding=False', language: 'cython')
add_project_arguments('-X binding=True', language: 'cython')
add_project_arguments('-X c_api_binop_methods=True', language: 'cython')
add_project_arguments('-X cdivision=True', language: 'cython')
add_project_arguments('-X cpow=True', language: 'cython')
Expand Down
8 changes: 4 additions & 4 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2236,9 +2236,9 @@ def get_gcd(order):
EXAMPLES::

sage: sage.arith.misc.get_gcd(4000)
<built-in method gcd_int of sage.rings.fast_arith.arith_int object at ...>
<bound method arith_int.gcd_int of <sage.rings.fast_arith.arith_int object at ...>
sage: sage.arith.misc.get_gcd(400000)
<built-in method gcd_longlong of sage.rings.fast_arith.arith_llong object at ...>
<bound method arith_llong.gcd_longlong of <sage.rings.fast_arith.arith_llong object at ...>
sage: sage.arith.misc.get_gcd(4000000000)
<function gcd at ...>
"""
Expand All @@ -2258,9 +2258,9 @@ def get_inverse_mod(order):
EXAMPLES::

sage: sage.arith.misc.get_inverse_mod(6000)
<built-in method inverse_mod_int of sage.rings.fast_arith.arith_int object at ...>
<bound method arith_int.inverse_mod_int of <sage.rings.fast_arith.arith_int object at ...>
sage: sage.arith.misc.get_inverse_mod(600000)
<built-in method inverse_mod_longlong of sage.rings.fast_arith.arith_llong object at ...>
<bound method arith_llong.inverse_mod_longlong of <sage.rings.fast_arith.arith_llong object at ...>
sage: sage.arith.misc.get_inverse_mod(6000000000)
<function inverse_mod at ...>
"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/categories/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@
This ``base_ring`` method is actually overridden by
:meth:`sage.structure.category_object.CategoryObject.base_ring`::

sage: H.base_ring.__module__ # needs sage.modules
sage: H.base_ring.__module__

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Check warning on line 772 in src/sage/categories/modules.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Warning: Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'

Variable 'H' referenced here was set only in doctest marked '# needs sage.modules'
'sage.structure.category_object'

Here we call it directly::

Expand Down
1 change: 1 addition & 0 deletions src/sage/categories/primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ class SubcategoryMethods:
to use Sage's introspection tools to recover where it's implemented::

sage: x._repr_.__module__
'sage.structure.element_wrapper'
sage: sage.misc.sageinspect.sage_getfile(x._repr_)
'.../sage/structure/element_wrapper.pyx'

Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/sf/classical.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def init():
sage: sage.combinat.sf.classical.conversion_functions = {}
sage: init()
sage: sage.combinat.sf.classical.conversion_functions[('Schur', 'powersum')]
<built-in function t_SCHUR_POWSYM_symmetrica>
<cyfunction t_SCHUR_POWSYM_symmetrica at ...>

The following checks if the bug described in :issue:`15312` is fixed. ::

Expand Down
36 changes: 0 additions & 36 deletions src/sage/graphs/base/static_sparse_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1509,42 +1509,6 @@ cdef class StaticSparseBackend(CGraphBackend):
yield self._vertex_to_labels[u]
seen.add(u)

def add_vertex(self, v):
r"""
Addition of vertices is not available on an immutable graph.

EXAMPLES::

sage: g = DiGraph(graphs.PetersenGraph(), data_structure='static_sparse')
sage: g.add_vertex(1)
Traceback (most recent call last):
...
TypeError: this graph is immutable and so cannot be changed
sage: g.add_vertices([1,2,3])
Traceback (most recent call last):
...
TypeError: this graph is immutable and so cannot be changed
"""
(<StaticSparseCGraph> self._cg).add_vertex(v)

def del_vertex(self, v):
r"""
Removal of vertices is not available on an immutable graph.

EXAMPLES::

sage: g = DiGraph(graphs.PetersenGraph(), data_structure='static_sparse')
sage: g.delete_vertex(1)
Traceback (most recent call last):
...
TypeError: this graph is immutable and so cannot be changed
sage: g.delete_vertices([1,2,3])
Traceback (most recent call last):
...
TypeError: this graph is immutable and so cannot be changed
"""
(<StaticSparseCGraph> self._cg).del_vertex(v)


@cython.binding(True)
def _run_it_on_static_instead(f):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/strongly_regular_db.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def is_RSHCD(int v, int k, int l, int mu):

sage: from sage.graphs.strongly_regular_db import is_RSHCD
sage: t = is_RSHCD(64,27,10,12); t # needs sage.combinat sage.modules
[<built-in function SRG_from_RSHCD>, 64, 27, 10, 12]
[<cyfunction SRG_from_RSHCD at ...>, 64, 27, 10, 12]
sage: g = t[0](*t[1:]); g # needs sage.combinat sage.modules
Graph on 64 vertices
sage: g.is_strongly_regular(parameters=True) # needs sage.combinat sage.modules
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/sage0.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def _repr_(self):
EXAMPLES::

sage: sage0(4).gcd
<built-in method gcd of sage.rings.integer.Integer object at 0x...>
<bound method PrincipalIdealDomainElement.gcd of 4>
"""
return str(self._obj.parent().eval('%s.%s' % (self._obj._name,
self._name)))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ cpdef poison_currRing(frame, event, arg):
sage: from sage.libs.singular.ring import poison_currRing
sage: sys.settrace(poison_currRing)
sage: sys.gettrace()
<built-in function poison_currRing>
<cyfunction poison_currRing at ...>
sage: sys.settrace(previous_trace_func) # switch it off again
"""
global currRing
Expand Down
2 changes: 0 additions & 2 deletions src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2695,8 +2695,6 @@ cdef class Matroid(SageObject):
if not self._is_independent(X):
yield X

dependent_r_sets = deprecated_function_alias(38057, dependent_sets)

cpdef SetSystem dependent_sets(self, long k):
r"""
Return the dependent sets of fixed size.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/c3_controlled.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
sage: x._bases
[5, 2]
sage: x._key
<built-in function identity>
<cyfunction identity at ...>
sage: x._key(10)
10

Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/lazy_attribute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cdef class _lazy_attribute():
sage: Parent.element_class.__name__
'element_class'
sage: Parent.element_class.__module__
'sage.misc.lazy_attribute'
'sage.structure.parent'
"""
raise NotImplementedError("Only instantiate wrapper python class")

Expand Down
12 changes: 12 additions & 0 deletions src/sage/misc/lazy_import.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cdef class LazyImport:
cdef readonly object _object # The actual object if imported, None otherwise
cdef object _module
cdef object _name
cdef object _as_name
cdef object _namespace
cdef bint _at_startup
cdef object _deprecation
cdef object _feature

cdef inline get_object(self)
cpdef _get_object(self)
9 changes: 0 additions & 9 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ cdef class LazyImport():
...
TypeError: no conversion of this rational to integer
"""
cdef readonly _object # The actual object if imported, None otherwise
cdef _module
cdef _name
cdef _as_name
cdef _namespace
cdef bint _at_startup
cdef _deprecation
cdef _feature

def __init__(self, module, name, as_name=None, at_startup=False, namespace=None,
deprecation=None, feature=None):
"""
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ py.install_sources(
'latex_macros.py',
'latex_standalone.py',
'lazy_format.py',
'lazy_import.pxd',
'lazy_import_cache.py',
'lazy_list.pxd',
'lazy_string.pxd',
Expand Down
6 changes: 5 additions & 1 deletion src/sage/misc/persist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ comp_other = bz2

from sage.misc.sage_unittest import TestSuite
from sage.misc.superseded import deprecation
from sage.misc.lazy_import cimport LazyImport

# We define two global dictionaries `already_pickled` and
# `already_unpickled`, which are intended to help you to implement
Expand Down Expand Up @@ -331,7 +332,10 @@ def dumps(obj, compress=True):
if make_pickle_jar:
picklejar(obj)
try:
ans = obj.dumps(compress)
type_obj = type(obj)
if type_obj is LazyImport:
type_obj = type((<LazyImport>obj).get_object())
ans = type_obj.dumps(obj, compress)
except (AttributeError, RuntimeError, TypeError):
ans = _base_dumps(obj, compress=compress)
already_pickled = {}
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def is_function_or_cython_function(obj):
sage: is_function_or_cython_function(_mul_parent)
True
sage: is_function_or_cython_function(Integer.digits) # unbound method
False
True
sage: is_function_or_cython_function(Integer(1).digits) # bound method
False

Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/hom_finite_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens):
sage: Frob = k.frobenius_endomorphism()
sage: embed = Frob.fixed_field()[1]
sage: embed.__reduce__() # indirect doctest
(<built-in function unpickle_map>,
(<cyfunction unpickle_map at ...>,
(<class 'sage.rings.finite_rings.hom_prime_finite_field.FiniteFieldHomomorphism_prime'>,
Set of field embeddings from Finite Field of size 5 to Finite Field in t of size 5^3,
{},
Expand Down
8 changes: 4 additions & 4 deletions src/sage/sets/disjoint_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ cdef class DisjointSet_class(SageObject):

sage: d = DisjointSet(5)
sage: d.__reduce__()
(<built-in function DisjointSet>, (5,), [0, 1, 2, 3, 4])
(<cyfunction DisjointSet at ...>, (5,), [0, 1, 2, 3, 4])

::

sage: d.union(2, 4)
sage: d.union(1, 3)
sage: d.__reduce__()
(<built-in function DisjointSet>, (5,), [0, 1, 2, 1, 2])
(<cyfunction DisjointSet at ...>, (5,), [0, 1, 2, 1, 2])
"""
return DisjointSet, (self._nodes.degree,), self.__getstate__()

Expand Down Expand Up @@ -730,7 +730,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
{{0}, {1}, {2}, {3}, {4}}
sage: d = _
sage: d.__reduce__()
(<built-in function DisjointSet>,
(<cyfunction DisjointSet at ...>,
([0, 1, 2, 3, 4],),
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)])

Expand All @@ -739,7 +739,7 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
sage: d.union(2, 4)
sage: d.union(1, 3)
sage: d.__reduce__()
(<built-in function DisjointSet>,
(<cyfunction DisjointSet at ...>,
([0, 1, 2, 3, 4],),
[(0, 0), (1, 1), (2, 2), (3, 1), (4, 2)])
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/structure/category_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ cdef class CategoryObject(SageObject):
sage: F.base_ring() # needs sage.modules
Integer Ring
sage: F.__class__.base_ring # needs sage.modules
<method 'base_ring' of 'sage.structure.category_object.CategoryObject' objects>
<cyfunction CategoryObject.base_ring at ...>

Note that the coordinates of the elements of a module can lie
in a bigger ring, the ``coordinate_ring``::
Expand All @@ -604,7 +604,7 @@ cdef class CategoryObject(SageObject):
sage: F.base_ring() # needs sage.combinat sage.modules
Rational Field
sage: F.__class__.base_ring # needs sage.combinat sage.modules
<method 'base_ring' of 'sage.structure.category_object.CategoryObject' objects>
<cyfunction CategoryObject.base_ring at ...>

sage: # needs sage.modules
sage: E = CombinatorialFreeModule(ZZ, [1,2,3])
Expand All @@ -613,7 +613,7 @@ cdef class CategoryObject(SageObject):
sage: H.base_ring()
Integer Ring
sage: H.__class__.base_ring
<method 'base_ring' of 'sage.structure.category_object.CategoryObject' objects>
<cyfunction CategoryObject.base_ring at ...>

.. TODO::

Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/factory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ cdef class UniqueFactory(SageObject):
sage: a = test_factory(1, 2)
Making object (1, 2)
sage: test_factory.reduce_data(a)
(<built-in function generic_factory_unpickle>,
(<cyfunction generic_factory_unpickle at ...>,
(<sage.structure.test_factory.UniqueFactoryTester object at ...>,
(...),
(1, 2),
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/list_clone.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ cdef class ClonableArray(ClonableElement):
sage: loads(dumps(el))
[1, 2, 4]
sage: t = el.__reduce__(); t
(<built-in function _make_array_clone>,
(<cyfunction _make_array_clone at ...>,
(<class 'sage.structure.list_clone_demo.IncreasingArray'>,
<sage.structure.list_clone_demo.IncreasingArrays_with_category object at ...>,
[1, 2, 4],
Expand Down Expand Up @@ -1729,7 +1729,7 @@ cdef class ClonableIntArray(ClonableElement):
sage: loads(dumps(el))
[1, 2, 4]
sage: t = el.__reduce__(); t
(<built-in function _make_int_array_clone>,
(<cyfunction _make_int_array_clone at ...>,
(<class 'sage.structure.list_clone_demo.IncreasingIntArray'>,
<sage.structure.list_clone_demo.IncreasingIntArrays_with_category object at ...>,
[1, 2, 4],
Expand Down
Loading
Loading