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

Re-expose default_encoders and allow changing them in CBOREncoder again #226

Open
1 task done
oxij opened this issue Mar 16, 2024 · 0 comments · May be fixed by #227
Open
1 task done

Re-expose default_encoders and allow changing them in CBOREncoder again #226

oxij opened this issue Mar 16, 2024 · 0 comments · May be fixed by #227

Comments

@oxij
Copy link

oxij commented Mar 16, 2024

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

Please, re-expose default_encoders and probably other similar attributes that were public before version 5.5.0 and allow overriding default_encoders in CBOREncoder. A new __init__ parameter for it would be nice.

Use case

Before 5.5.0 in pwebarc I did

encoders = cbor2.encoders.default_encoders.copy()
if abridged:
    encoders[bytes] = _t.cast(_t.Any, self.encode_cbor_abridged)
    encoders[str] = _t.cast(_t.Any, self.encode_cbor_abridged)
self.encoder = _cbor2.CBOREncoder(_io.BytesIO(), default = self.encode_cbor)
self.encoder._encoders = encoders

(I want to use self.encode_cbor_abridged for long strings and bytes when abbreviation is enabled, default_encoders for all the default things, and self.encode_cbor for my custom stuff)

after 5.5.0 default_encoders and such are no longer exposed as a public interface and CBOREncoder()._encoders is now read-only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant