8000 ENH: Chain exceptions to give better error messages for invalid PEP3118 format strings by eric-wieser · Pull Request #11119 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Chain exceptions to give better error messages for invalid PEP3118 format strings #11119

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

Merged
merged 1 commit into from
Oct 3, 2018

Conversation

eric-wieser
Copy link
Member

Sample console output:

In [1]: from ctypes import c_wchar

In [2]: x = c_wchar * 3

In [3]: np.array(x())
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in _dtype_from_pep3118(spec)
    486
--> 487     dtype, align = __dtype_from_pep3118(stream, is_subdtype=False)
    488     return dtype

~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in __dtype_from_pep3118(stream, is_subdtype)
    558         else:
--> 559             raise ValueError("Unknown PEP 3118 data type specifier %r" % stream.s)
    560

ValueError: Unknown PEP 3118 data type specifier 'u'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-3-f8a17df3aa24> in <module>()
----> 1 np.array(x())

ValueError: '<u' is not a valid PEP 3118 buffer format string

@eric-wieser
Copy link
Member Author

Where would be a good place for PyArray_ChainExceptionsCause to move to? Perhaps npy_compat.h as npy_PyErr_ChainExceptionsCause?

PyErr_Format(PyExc_ValueError,
"'%s' is not a valid PEP 3118 buffer format string", buf);
PyArray_ChainExceptionsCause(exc, val, tb);
Copy link
Member
@charris charris May 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the prototype for PyArray_ChainExceptionsCause needs to be in an include file, it is defined in arrayobject.c.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which include file would you recommend? npy_compat.h?

@charris
Copy link
Member
charris commented May 29, 2018

We might want to reconsider the layout of the include files at some point.

…18 format strings

Sample console output:
```
In [1]: from ctypes import c_wchar

In [2]: x = c_wchar * 3

In [3]: np.array(x())
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in _dtype_from_pep3118(spec)
    486
--> 487     dtype, align = __dtype_from_pep3118(stream, is_subdtype=False)
    488     return dtype

~\Repos\numeric-python\numpy\build\testenv\Lib\site-packages\numpy\core\_internal.py in __dtype_from_pep3118(stream, is_subdtype)
    558         else:
--> 559             raise ValueError("Unknown PEP 3118 data type specifier %r" % stream.s)
    560

ValueError: Unknown PEP 3118 data type specifier 'u'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-3-f8a17df3aa24> in <module>()
----> 1 np.array(x())

ValueError: '<u' is not a valid PEP 3118 buffer format string
```
@eric-wieser eric-wieser force-pushed the chain-PEP3118_exception branch from 1515b7e to b6e03a4 Compare September 23, 2018 16:26
@eric-wieser
Copy link
Member Author

Moved to np_compat3k.h and prefixed with npy_

@mattip mattip merged commit 043a840 into numpy:master Oct 3, 2018
@mattip
Copy link
Member
mattip commented Oct 3, 2018

Thanks Eric

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
0