Skip to content
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

Remove the use of cTrait.default_value to set the default value #1632

Merged
merged 5 commits into from
Apr 20, 2022

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Apr 19, 2022

The use of cTrait.default_value to set the default value type and default value was deprecated in 2019, in #620. This PR removes that deprecated support. To set the default value type and default value for a CTrait or cTrait instance, use set_default_value.

Checklist

  • Tests
  • Update API reference (docs/source/traits_api_reference) N/A
  • Update User manual (docs/source/traits_user_manual) N/A
  • Update type annotation hints in traits-stubs N/A

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

Mostly LGTM with a couple of comments/questions.

traits/ctraits.c Outdated Show resolved Hide resolved
traits/ctraits.c Outdated Show resolved Hide resolved
mdickinson and others added 3 commits April 20, 2022 08:21
@mdickinson
Copy link
Member Author

@rahulporuri Thanks for the review! I've updated. If you have bandwidth for another look, that would be much appreciated.

@mdickinson mdickinson requested a review from rahulporuri April 20, 2022 07:36
Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM with a question

+----------------------------------------------------------------------------*/

static PyObject *
_trait_default_value(trait_object *trait, PyObject *args)
_trait_default_value(trait_object *trait, PyObject *Py_UNUSED(ignored))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to define a second argument to the _trait_default_value function, which is then marked as ignored (IIUC this is done only to silence compiler warnings)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a second argument is required here. You can see lots of uses of this pattern in the CPython source, too. The function has to be of type PyCFunction (docs here), which is defined as

typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);

Copy link
Member Author

Choose a reason for hiding this comment

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

and yes, the Py_UNUSED is there to silence compiler warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the reference and explanation. Still LGTM

@mdickinson mdickinson merged commit 99d0aa7 into main Apr 20, 2022
@mdickinson mdickinson deleted the cleanup/remove-deprecated-default-value-for-set branch April 20, 2022 08:05
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.

2 participants