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
.pxd files should not use PY_MAJOR_VERSION compile-time variable #25549
Comments
This comment has been minimized.
This comment has been minimized.
New commits:
|
Commit: |
Author: Jeroen Demeyer |
comment:4
What is the rationale for this: cpdef inline str bytes_to_str(b, encoding=None, errors=None):
@@ -64,14 +51,13 @@ cpdef inline str bytes_to_str(b, encoding=None, errors=None):
...
TypeError: expected bytes, list found
"""
- if not isinstance(b, bytes):
+ if type(b) is not bytes:
raise TypeError(f"expected bytes, {type(b).__name__} found") That's to say, why don't you allow sub-types of |
comment:5
Replying to @simon-king-jena:
Mainly to be on the safe side. I have no idea what the C API does with subclasses of Whenever a real use case for |
Reviewer: Simon King |
comment:6
Replying to @jdemeyer:
OK. Apart from that, the code looks fine to me, all tests pass, and you added a test that shows that the bug is fixed. |
Changed branch from u/jdemeyer/_pxd_files_should_not_use_py_major_version_compile_time_variable to |
Changed commit from |
comment:8
I guess I don't mind, but what even is the use case for this:
? IMO |
comment:9
Or for that matter, what's wrong with just documenting "so and so requires the following compile-time variables to be defined"? |
comment:10
On the third hand, I think it's common enough, especially writing code that is Python 2/3-compatible, to want to have the Python version as a compile-time variable, so maybe Cython really ought to provide this by default... |
comment:11
Replying to @embray:
Third-party code already using Sage that wants to be Python 2/3 compatible. |
comment:12
Replying to @embray:
This may be. However, Cython currently doesn't provide it. In fact I did try to use |
comment:13
That's fine. It just sucks that in order to write such code in a pxd file it's...basically impossible unless you move it into a pure C file. Wild-haired idea: allow some directives in Cython files to provide compile-time variables, with short Not sure how that would work when compiling modules with functions imported from .pxd files, if it should even work at all. |
comment:14
Replying to @embray:
I'm not entirely convinced here. In most cases, you can write Python 2/3 compatible Cython code without needing the |
comment:15
True, but I think this demonstrates that there's a case for it. You can also write such code with normal |
Since the Cython code is almost C anyway, the easiest solution is probably to implement it actually in C (replacing the
IF
by#if
).CC: @simon-king-jena @embray
Component: cython
Author: Jeroen Demeyer
Branch:
85451ee
Reviewer: Simon King
Issue created by migration from https://trac.sagemath.org/ticket/25549
The text was updated successfully, but these errors were encountered: