Skip to content

Add embedsignature for special methods#6764

Merged
scoder merged 6 commits intocython:masterfrom
user202729:embed-signature-special
Apr 20, 2025
Merged

Add embedsignature for special methods#6764
scoder merged 6 commits intocython:masterfrom
user202729:embed-signature-special

Conversation

@user202729
Copy link
Copy Markdown
Contributor

@user202729 user202729 commented Mar 27, 2025

Partial fix for #1577 .

Will work when the method already has a docstring, but otherwise no guarantee. The reason is explained in the code.

Unfortunately I don't know how to fix it properly yet.


Looks like the test failure with limited API is existing bug rather than caused by this one? It is showing the superclass's docstring.

@user202729
Copy link
Copy Markdown
Contributor Author

Indeed, it looks like the bug is not introduced by this pull request.

With latest master, without this pull request:

a.pyx:

# cython: binding=True, language_level=3
import cython

cdef class A:
	def __call__(self, int a, float b):
		"""
		hello world
		"""
		print(1)

print(A.__call__.__doc__)

[tmp]$ CFLAGS=-DPy_LIMITED_API=0x03090000 cythonize -i a.pyx
Compiling /tmp/a.pyx because it changed.
[1/1] Cythonizing /tmp/a.pyx
[tmp]$ python -c "import a"
Call self as a function.
[tmp]$ rm -f a.c a.cpython-*
[tmp]$ cythonize -i a.pyx
Compiling /tmp/a.pyx because it changed.
[1/1] Cythonizing /tmp/a.pyx
[tmp]$ python -c "import a"

                hello world

What should I do (it shouldn't be in the scope of this pull request to also fix that issue?)

@da-woods
Copy link
Copy Markdown
Contributor

da-woods commented Apr 1, 2025

I think this is something where we can live with the Limited API not working quite right (especially since it seems to be pre-existing).

If you do

cdef extern from *:
    int CYTHON_COMPILING_IN_LIMITED_API

limited_api_on = True if CYTHON_COMPILING_IN_LIMITED_API else False

(or something similar) then you can see that's it's activated and disable the individual test.

@user202729
Copy link
Copy Markdown
Contributor Author

Any idea why include.pyxinclude "testinclude.pxi" works but
include "skip_limited_api_helper.pxi" is failing? Maybe because of the initial test or the underscore?

@scoder
Copy link
Copy Markdown
Contributor

scoder commented Apr 2, 2025

Not sure about the first but the test runner automatically copies all files called "currenttestname*.*" into the test execution directory (every test has its own directory) but not apparently unrelated files.

@user202729
Copy link
Copy Markdown
Contributor Author

user202729 commented Apr 2, 2025

Maybe that's the cause.

    def related_files(self, test_directory, module_name):
        is_related = re.compile('%s_.*[.].*' % module_name).match
        return [filename for filename in list_unchanging_dir(test_directory)
                if is_related(filename)]

What is your recommendation here, copy paste the function to every file as before? (the alternative is to modify related_files to parse for include or some magic comment, I guess?)

@user202729
Copy link
Copy Markdown
Contributor Author

user202729 commented Apr 3, 2025

… maybe the cause is I forget to git add it.

I guess I can run CI on my fork too, then no need for approval for debugging on my side. Let's see. https://github.com/user202729/cython/actions/runs/14247014745

Edit: yes looks like they all passes.

@scoder scoder merged commit 2f54752 into cython:master Apr 20, 2025
1 check passed
@scoder
Copy link
Copy Markdown
Contributor

scoder commented Apr 20, 2025

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants