Conversation
added 5 commits
January 31, 2026 12:14
* Support for using Encoder via context manager * Support for encoding sequences via context manager * Support for encoding sets via context manager
Owner
|
What a nice PR! Thanks. I will need some time to review it and test on old versions of Python to be sure that everything is OK and compatible. |
Owner
|
I look briefly at the tox build and the code, as it is, is not compatible with Python 2.7. In particular, there is this error: This (internal) class does not exist for Python 2.7. There are other issues (formatting, ...) but they are easier to fix. |
added 7 commits
February 4, 2026 19:52
Author
|
I fixed the bug in Python 2.7 and fixed some minor issues reported in tox. There's a problem with Python 3.9, and I temporarily disabled it, but I can't easily fix it. Can you try? |
Owner
|
I will look at Python 3.9. A note: since it is a new feature and not a bug fix, the new version will be "3.2.0", not "3.1.1" (semver). I can take care of it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces a new context-manager based API for both Encoder and Decoder, aimed at improving readability and usability while remaining fully backward compatible with the existing API.
The new API allows encoding and decoding ASN.1 structures using Python with blocks (e.g. with encoder.sequence():), without breaking or modifying the current behavior.
Added context manager support to Encoder and Decoder
Introduced helper methods (Encoder.sequence() and Encoder.set()) to replace explicit enter() / leave() calls
Existing code using the old API continues to work unchanged
New tests demonstrate equivalence between the legacy API and the context-manager–based API
All existing and new tests are passing
I was only able to test this change on Python 3.13, as this is the only version available in my environment
The goal is to make complex ASN.1 structures easier to read, write, and maintain, while preserving full compatibility with current users of the library.
Feedback is very welcome