-
Notifications
You must be signed in to change notification settings - Fork 62
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
Make Exceptions raised in nim catchable as native python Exception subclasses #300
Draft
PaarthShah
wants to merge
19
commits into
yglukhov:master
Choose a base branch
from
PaarthShah:catchable-python-exceptions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
64c81ab
Initial implementation: ZeroDivisionError + refactor
PaarthShah 5275340
AssertionError
PaarthShah ed8b920
AttributeError
PaarthShah 58f9352
IOError
PaarthShah 31fef23
EOFError
PaarthShah 2e4d9df
FloatingPointError
PaarthShah 1b286ea
IndexError
PaarthShah 62cd7e1
KeyError
PaarthShah 47bf99a
Formatting
PaarthShah 98d04a9
Move Exception conversion to nim_py_marshalling
PaarthShah 7049a28
Raised Exceptions are a subclass of nimpy.NimPyException
PaarthShah 6efb9cb
Add tests to validate raised exception subclass
PaarthShah 48bed2a
ImportError
PaarthShah 4b74c26
RecursionError
PaarthShah 7b6a53b
MemoryError
PaarthShah 192c6e2
Fix generic warnings related to deprecated types
PaarthShah ed1a391
OSError
PaarthShah c7961e1
TypeError
PaarthShah 1887bf0
Harden tests
PaarthShah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ type | |
|
||
Py_BuildValue*: proc(f: cstring): PPyObject {.pyfunc, varargs.} | ||
PyTuple_New*: proc(sz: Py_ssize_t): PPyObject {.pyfunc.} | ||
PyTuple_Pack*: proc(sz: Py_ssize_t): PPyObject {.pyfunc, varargs.} | ||
PyTuple_Size*: proc(f: PPyObject): Py_ssize_t {.pyfunc.} | ||
PyTuple_GetItem*: proc(f: PPyObject, i: Py_ssize_t): PPyObject {.pyfunc.} | ||
PyTuple_SetItem*: proc(f: PPyObject, i: Py_ssize_t, v: PPyObject): cint {.pyfunc.} | ||
|
@@ -90,7 +91,6 @@ type | |
PyErr_Clear*: proc() {.pyfunc.} | ||
PyErr_SetString*: proc(o: PPyObject, s: cstring) {.pyfunc.} | ||
PyErr_Occurred*: proc(): PPyObject {.pyfunc.} | ||
PyExc_TypeError*: PPyObject | ||
|
||
PyCapsule_New*: proc(p: pointer, name: cstring, destr: proc(o: PPyObject) {.pyfunc.}): PPyObject {.pyfunc.} | ||
PyCapsule_GetPointer*: proc(c: PPyObject, name: cstring): pointer {.pyfunc.} | ||
|
@@ -114,17 +114,57 @@ type | |
PyExc_BaseException*: PPyObject # should always match any exception? | ||
PyExc_Exception*: PPyObject | ||
PyExc_ArithmeticError*: PPyObject | ||
PyExc_FloatingPointError*: PPyObject | ||
PyExc_OverflowError*: PPyObject | ||
PyExc_ZeroDivisionError*: PPyObject | ||
PyExc_AssertionError*: PPyObject | ||
PyExc_OSError*: PPyObject | ||
PyExc_IOError*: PPyObject # in Python 3 IOError *is* OSError | ||
PyExc_ValueError*: PPyObject | ||
#PyExc_AttributeError*: PPyObject | ||
# PyExc_BlockingIOError # no | ||
# PyExc_BrokenPipeError | ||
# PyExc_BufferError | ||
# PyExc_ChildProcessError | ||
# PyExc_ConnectionAbortedError | ||
# PyExc_ConnectionError | ||
# PyExc_ConnectionRefusedError | ||
# PyExc_ConnectionResetError | ||
PyExc_EOFError*: PPyObject | ||
PyExc_MemoryError*: PPyObject | ||
# PyExc_FileExistsError | ||
# PyExc_FileNotFoundError | ||
PyExc_FloatingPointError*: PPyObject | ||
# PyExc_GeneratorExit | ||
PyExc_ImportError*: PPyObject | ||
# PyExc_IndentationError # no | ||
PyExc_IndexError*: PPyObject | ||
# PyExc_InterruptedError | ||
PyExc_IOError*: PPyObject # in Python 3 IOError *is* OSError | ||
# PyExc_IsADirectoryError | ||
PyExc_KeyError*: PPyObject | ||
# PyExc_KeyboardInterrupt | ||
# PyExc_LookupError | ||
PyExc_MemoryError*: PPyObject | ||
# PyExc_ModuleNotFoundError | ||
# PyExc_NameError | ||
# PyExc_NotADirectoryError | ||
# PyExc_NotImplementedError | ||
PyExc_OSError*: PPyObject | ||
PyExc_OverflowError*: PPyObject | ||
# PyExc_PermissionError | ||
# PyExc_ProcessLookupError | ||
PyExc_RecursionError*: PPyObject | ||
# PyExc_ReferenceError | ||
# PyExc_RuntimeError | ||
# PyExc_StopAsyncIteration | ||
# PyExc_StopIteration | ||
# PyExc_SyntaxError | ||
# PyExc_SystemError | ||
# PyExc_SystemExit | ||
# PyExc_TabError | ||
# PyExc_TimeoutError | ||
PyExc_TypeError*: PPyObject | ||
# PyExc_UnboundLocalError | ||
# PyExc_UnicodeDecodeError | ||
# PyExc_UnicodeEncodeError | ||
# PyExc_UnicodeError | ||
# PyExc_UnicodeTranslateError | ||
PyExc_ValueError*: PPyObject | ||
PyExc_ZeroDivisionError*: PPyObject | ||
|
||
NimPyException*: PPyObject | ||
|
||
|
@@ -212,6 +252,7 @@ proc loadPyLibFromModule(m: LibHandle): PyLib = | |
|
||
load Py_BuildValue, "_Py_BuildValue_SizeT" | ||
load PyTuple_New | ||
load PyTuple_Pack | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.python.org/3.13/c-api/tuple.html |
||
load PyTuple_Size | ||
load PyTuple_GetItem | ||
load PyTuple_SetItem | ||
|
@@ -327,17 +368,20 @@ proc loadPyLibFromModule(m: LibHandle): PyLib = | |
load PyErr_NewException | ||
|
||
loadVar PyExc_ArithmeticError | ||
loadVar PyExc_FloatingPointError | ||
loadVar PyExc_OverflowError | ||
loadVar PyExc_ZeroDivisionError | ||
loadVar PyExc_AssertionError | ||
loadVar PyExc_OSError | ||
loadVar PyExc_IOError | ||
loadVar PyExc_ValueError | ||
loadVar PyExc_EOFError | ||
loadVar PyExc_MemoryError | ||
loadVar PyExc_FloatingPointError | ||
loadVar PyExc_ImportError | ||
loadVar PyExc_IndexError | ||
loadVar PyExc_IOError | ||
loadVar PyExc_KeyError | ||
loadVar PyExc_MemoryError | ||
loadVar PyExc_OSError | ||
loadVar PyExc_OverflowError | ||
loadVar PyExc_RecursionError | ||
loadVar PyExc_TypeError | ||
loadVar PyExc_ValueError | ||
loadVar PyExc_ZeroDivisionError | ||
|
||
if pl.pythonVersion.major == 3: | ||
pl.PyDealloc = deallocPythonObj[PyTypeObject3] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 mapped many new exceptions in from https://docs.python.org/3/c-api/exceptions.html#standard-exceptions, but most of these probably will not be required as they don't directly map to a standard library nim exception as per https://nim-lang.org/docs/exceptions.html.
Before I move this out of draft, I'll make a point of removing the commented/unmapped entries.
I didn't delete any, but I made a point of alphabetizing them