[Python-Dev] Understanding the buffer API

Stefan Krah stefan at bytereef.org
Sat Aug 4 17:39:17 CEST 2012


Nick Coghlan <ncoghlan at gmail.com> wrote:
> I took Jeff's question as being slightly different and applying in the
> following situations:

I think I attempted to answer the same thing. :)


> 1. If the consumer has NOT requested format data, can the provider
> return accurate format data anyway, if that's easier than returning
> NULL but is consistent with doing so?

No, this is definitely disallowed by the PEP (PyBUF_FORMAT):

"If format is not explicitly requested then the format must be returned as
 NULL (which means "B", or unsigned bytes)."


> 2. The consumer has NOT requested shape data, can shape data be
> provided anyway, if that's easier than returning NULL but is
> consistent with doing so?

Also explicitly disallowed (PyBUF_ND):

"If this is not given then shape will be NULL."


> 3. The consumer has NOT requested strides data, can strides data be
> provided anyway, if that's easier than returning NULL but is
> consistent with doing so?

This is not explicitly disallowed, but IMO the intent is that strides
should also be NULL in that case. For example, strides==NULL might be
used for a quick C-contiguity test.


Stefan Krah





More information about the Python-Dev mailing list