feat: add repr
kwarg to field
function and Field
C struct
#543
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.
I picked up ticket #492 to help contribute this feature, as I'd really like to use this library for a project which requires excluding fields (a linked list with mutual references which would produce infinite loop if
repr
'd).To begin, I have done the following:
repr
which controls the inclusion of the field in the generated__repr__
string for the struct.repr
to theField
C struct to store the value of therepr
keyword argument.Field
C struct docstring to include details about the newrepr
kwarg.Then to complete the feature I followed the lead of the other lookup dictionaries (ending in
_lk
) likedefaults_lk
, and used a list that was converted to a tuple, as I'm sure you're familiar. For boolean configuration I have only allowed this to bePy_True
orPy_False
, and defaulting toPy_True
if the value type is not aField
object. With a little extra logic here this could be extended to handle arbitary callables if desired.I tried to follow the example of how to represent
repr
in C from where other arguments useint
to represent booleans. Please take a careful look at this to ensure it fits the house style.Update I've added tests and remembered to also implement this feature in the
__rich_repr__
method internal too.Update I've implemented support for callables as described in the original ticket
Update I reviewed the memory management (incrementing/decrementing), refcount tests continue to pass