-
Notifications
You must be signed in to change notification settings - Fork 85
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
Return "PyErr_Format" calls in "traits/ctraits.c" #1640
Conversation
instead of explicitly returning NULL modified: traits/ctraits.c
I wasn't sure of one change in this PR and CI seems to agree -
|
the question now is - should the static void become a static int, like the other similar invalid_attribute_error function modified: traits/ctraits.c
traits/ctraits.c
Outdated
static void | ||
unknown_attribute_error(has_traits_object *obj, PyObject *name) | ||
{ | ||
return PyErr_Format( |
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.
should this function become a static int
instead of a static void
like the similar invalid_attribute_error
function?
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 don't think that would buy us anything, except consistency. The static int
on the other functions is a little odd, because the return value is mostly useless - it doesn't pass on any information. It's a minor convenience if you happen to be calling invalid_attribute_error
from a function that expects to return an int
, but I don't see a clear reason why that would always be the case - you might just as well be calling invalid_attribute_error
from a function that expects to return a pointer instead.
trait_object modified: traits/ctraits.c
LGTM. For commit 8c3bf24, there's no good reason that I can see for |
Gah. Sorry. I meant "changed to have return type |
modified: docs/source/traits_user_manual/custom.rst
traits/ctraits.c
Outdated
@@ -2911,7 +2911,7 @@ trait_new(PyTypeObject *trait_type, PyObject *args, PyObject *kw) | |||
} | |||
|
|||
if ((kind >= 0) && (kind <= 8)) { | |||
trait = (trait_object *)PyType_GenericNew(trait_type, args, kw); | |||
trait = (PyObject *)PyType_GenericNew(trait_type, args, kw); |
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.
You want to do the cast at the return trait
line. trait->getattr
and trait->setattr
won't make sense for a general PyObject *
.
It's just a type declaration: There's a cast in |
modified: traits/ctraits.c
modified: traits/ctraits.c
modified: traits/ctraits.c
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.
LGTM
Also changes the return type of `trait_new` to eliminate the need for the `(newfunc)` cast. (cherry picked from commit 576b6b0)
As mentioned in an earlier comment #1631 (comment), this PR returns
PyErr_Format
instead of explicitly returningNULL
.Checklist
TestsUpdate API reference (docs/source/traits_api_reference
)Update User manual (docs/source/traits_user_manual
)Update type annotation hints intraits-stubs