-
Notifications
You must be signed in to change notification settings - Fork 59
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
Moved global decoder dicts to decoder object #225
base: master
Are you sure you want to change the base?
Moved global decoder dicts to decoder object #225
Conversation
@agronholm sorry for tagging you but I couldn't assign you as a reviewer. |
Hey @agronholm Just wanted to bump this to make sure it doesn't fly under the radar. |
@agronholm could you please take a look at this? |
This PR only seems to do this for the pure Python variant, not the C decoder? |
@agronholm Yes |
Well, that's not good. I can't have the two different implementations deviate any further. |
Does this implementation do anything that would result in a meaningful difference between Python and C? As far as I can tell, it does not. I'm not changing anything about how the decoder actually works. I'm just changing the scope of the function calling dictionary. There are obvious differences between the Python and C versions strictly because they are written in different languages, right? I don't see how changing the scope of the function calling dict would be any different. |
If you want to suggest things I can do to align the C version of the code with Python, I am happy to implement it. |
I think the proper place to start might be adding these new properties to |
I have developed c-extensions in the past, so that's not an issue. I can contribute for sure, but I don't think a contribution make sense here because this seems to be just a language difference. I just don't see the functional difference for the scope change because the function dictionary is only ever internally called. The current way that the Python code was written, having that dictionary be external created issues if you wanted to subclass it (which you can't do with the C-extension anyway). If you're really looking for feature parity between these two things, the way to approach it would be a substantial rewrite of either the Python code or the C-extension.
Regardless, the scoping of that dictionary is arbitrary given the current implementation of both the C and Python sections of the code. Please correct me if I'm wrong here, but this seems like an arbitrary change. I'm definitely happy to modify the c-extension if that's what is required. |
Wait, what?
If you subclass the C |
My apologies. I'll take a look at this. |
I'm having issues building the c-extension. It looks like a few things were changed in the c-extension that are causing the build to fail. I was wondering if it was just me, but it looks like the git actions failed to build it as well. I am capable of building 5.6.2, but 5.6.3 seemed to create two changes that are causing the build to fail:
source/decoder.c: In function ‘CBORDecoder_decode_epoch_date’:
source/decoder.c:1346:41: error: ‘_CBOR2_date_ordinal_offset’ undeclared (first use in this function)
1346 | ordinal = PyNumber_Add(num, _CBOR2_date_ordinal_offset);
|
source/decoder.c:1348:50: error: expected expression before ‘PyDateTime_Date’
1348 | ret = PyObject_CallMethodObjArgs(PyDateTime_Date, _CBOR2_str_fromordinal, ordinal, NULL);
| ^~~~~~~~~~~~~~~
source/decoder.c:1348:23: error: too few arguments to function ‘PyObject_CallMethodObjArgs’
1348 | ret = PyObject_CallMethodObjArgs(PyDateTime_Date, _CBOR2_str_fromordinal, ordinal, NULL);
| I'm compiling on: Any suggestions on how to resolve 2? |
It seems like there's a deeper problem that allows the failure to build the C extension to pass unnoticed. I'm making the appropriate changes to the tox and GitHub actions workflows to prevent this from happening in the future. |
As expected, this broke the CI. Well, this won't catch me by surprise ever again. |
Problem solved. |
This PR moves a
dict
of decoders from a global context to a class context.The purpose of this is to make subclassing
cbor2.CBORDecoder
for modification.This PR assists in resolving #224 as an intermediate step.