Comments (5)
I'm slightly amazed that this ever worked. It should be possible to do it manually via casting:
tmp = (<bytes>tmp).replace(b"f", b"H")
It isn't obvious to me whether this is something we should fix or not. It seems pretty unintuitive to be implicitly calling bytes
methods like this, but the worry is that lots of people are relying on it.
from cython.
This kind of breakage shouldn't happen in a point release, so it's an unintended regression. However, now that the regression is there, I wonder if we should really go back and change it again. I doubt that "lots of people" are relying on this specific behaviour. And it's easy to work around for users by making their code more explicit.
It worked in the sense that it creates one or two Python bytes objects, one before and one after the replacement, in which case the code throws away the first. We also allow cpp_string.decode()
, so it's not that far fetched.
However, the difference to cpp_string.decode()
is that it only creates one decoded string object, whereas the old cpp_string.replace()
could create two bytes objects, and that's not visible from the code. So making the conversion explicit really is an improvement to user code.
I'd keep the new behaviour, unless there is broader opposition.
But it's one more reason to be conservative with updates in point releases.
from cython.
Don't worry. Being able to mix C, C++ and Python APIs freely is at the core of Cython's feature set.
This is just a rather special case where C++ and Python methods with the same name exist and disagree. In that case, it seems reasonable that the C++ method of a C++ object is looked up first, before trying a conversion to Python and looking up the method there. So, if the old behaviour hadn't existed before, the new behaviour would be the expected, unsurprising one.
from cython.
I'm slightly amazed that this ever worked. It should be possible to do it manually via casting:
tmp = (<bytes>tmp).replace(b"f", b"H")
It isn't obvious to me whether this is something we should fix or not. It seems pretty unintuitive to be implicitly calling
bytes
methods like this, but the worry is that lots of people are relying on it.
Thanks, I had tried (tmp) but that didn't work, (tmp) on the other hand worked.
To me it's incredibly useful to be able to code like this so I hope you don't remove the option altogether, my project that's years in the making would probably not survive such an update (making every call explicit it might survive), but removing the ability to use Python calls like this altogether would be detrimental, after all Python has a lot of good libraries and functions for manipulating strings and such so you don't have to in C++, and these libraries are so optimized that it's often just as cheap if not cheaper to use the Python library, so why force users to do it in C++, you know what I mean?
I understand that's not what you're doing though, just expressing my concern about the hypothetical that this functionality would be removed in the future, I hope it doesn't.
Thanks for being reasonable as always and coming up with solutions/workarounds whenever possible.
from cython.
I wonder if it's worth putting a warning on the implicit conversion for an attribute lookup since it's an area where it's easy to get unexpected behaviour (and also missed attribute lookup becomes a runtime error rather than a compile time error).
I definitely don't want to stop anyone doing it deliberately but I wonder if it's unintended rather than intended in most cases.
from cython.
Related Issues (20)
- [BUG] Bug with limited API support in trivial program involving float literal HOT 5
- [BUG] Segmentation fault with Walrus-Operator and same named variables HOT 2
- [BUG] Generators after being cythonized cannot be inspect as generators HOT 13
- [ENH] Can Cython support the vector database function of redis? HOT 3
- [BUG] Function Wrapper yields unused-variable warning when compiled with pypy HOT 3
- [BUG] cppclass inheritance does not work with overloaded methods HOT 3
- [BUG] Deadlock in OpenMP Parallel Loop When Invoking LAPACK Functions in Cython>=3.0 HOT 4
- [BUG] Multi-line f-string literals do not adhere to """\ syntax HOT 1
- [bug] issues with "cppclass overloadable methods" HOT 1
- [ENH] Improve Cython install speed from source HOT 4
- [ENH] Reproducible output
- [ENH] Implement __Pyx_PyObject_LengthHint properly on the limited API HOT 1
- [BUG] 'except?' started failing in 3.0.10 HOT 16
- [ENH] Can Cython support match statement in Python? HOT 1
- [ENH] Restrict instance methods on extension types to the actual type HOT 2
- [ENH] Allow customization of cpdef enum to Py conversions
- [ENH] Compilation does not support importing cython module from another module HOT 4
- [ENH/BUG?] Enum as C array index value: Invalid index type 'Test' HOT 1
- [BUG] 3.0.10: test suite fails in `End-to-end coverage_cmd_src_pkg_layout` unit with `coverage` 7.4.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cython.