-
-
Notifications
You must be signed in to change notification settings - Fork 11k
DEP: Speed up WarnOnWrite deprecation in buffer interface #13977
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
Conversation
When a buffer interface does not request a writeable buffer, simply pass a read-only one when the warn on write flag is set. This is to give an easier way forward with avoiding the deprecation warnings: Simply do not ask for a writeable buffer. It will break code that expects writeable buffers but does not ask for them specifically a bit harder than would be nice. But since such code probably should ask for it specifically, this is likely fine (an RC release has to find out). The main reason for this is, that this way it plays very will with cython, which requests writeable buffers explicitly and if declared `const` is happy about read-only (so that using `const` is the best way to avoid the warning and makes code cleaner). Closes numpygh-13929, numpygh-13974
Hmm, the usual procedure is to forward port the release notes after a branch. Since this will be backported, it might be easier be easier to make it against 1.17.x to start with, then forward port the fix without the note to master. |
Can we add a test for this? |
* If a read-only buffer is requested on a read-write array, we return a | ||
* read-write buffer, which is dubious behavior. But that's why this call | ||
* is guarded by PyArray_ISWRITEABLE rather than (flags & | ||
* PyBUF_WRITEABLE). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment still applies, right? Perhaps just needs moving down lower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, will move it and rephrase slightly. It is not dubious in the sense that I think that is what the buffer protocol documents to happen.
if (array_might_be_written(self) < 0) { | ||
goto fail; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative to speeding this deprecation, is it sufficient to change this and the change below to:
if (!PyArray_CHKFLAGS(self, NPY_ARRAY_WARN_ON_WRITE)) {
readonly = PyArray_ISWRITEABLE(self); // keep the old weird behavior and comment above
}
else if ((flags & PyBUF_WRITEABLE) == PyBUF_WRITEABLE) {
// emit the warning from array_might_be_written
readonly = False;
}
else {
// return a readonly-array since doing so skirts the need for a warning
readonly = True
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I misunderstood the below, what I suggest is equivalent to what you already have and probably not any clearer.
* after a deprecation. This jumps the deprecation, but avoiding the | ||
* warning is not convenient here and a warning is given if a writeable | ||
* buffer is requested. (Warn on write is cleared if writeable is requested) | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear - the warn on write is already handled above in PyArray_FailUnlessWriteable
?
I will reopen this as a PR against 1.17.x, I hope I understood you right chuck. |
@seberg I think that is the path of least hassle. |
For future reference, you can change the target branch without opening a new PR. New PR is at gh-13993 |
When a buffer interface does not request a writeable buffer,
simply pass a read-only one when the warn on write flag is set.
This is to give an easier way forward with avoiding the deprecation
warnings: Simply do not ask for a writeable buffer.
It will break code that expects writeable buffers but does not
ask for them specifically a bit harder than would be nice.
But since such code probably should ask for it specifically, this
is likely fine (an RC release has to find out).
The main reason for this is, that this way it plays very will with
cython, which requests writeable buffers explicitly and if declared
const
is happy about read-only (so that usingconst
is the bestway to avoid the warning and makes code cleaner).
Closes gh-13929, gh-13974
There are two things: