Add doc[bool] conditional no-op toggle for with statements - #15
Merged
Merged
Conversation
…same expression if False.
There was a problem hiding this comment.
Pull request overview
This PR adds a conditional “no-op” toggle for the [] operator so doc[True] behaves normally while doc[False] returns a builder-like object that absorbs chained calls and with blocks, enabling conditional tags without conditional syntax around with.
Changes:
- Added
NullBuilder(a no-op context manager/builder) to swallow chained operations when a condition isFalse. - Extended
Builder.__getitem__to acceptbooland returnNullBuilderforFalse(orselfforTrue). - Added documentation and tests covering conditional tags, chaining behavior, and
NullBuilderbehavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_html5tagger.py | Adds tests for doc[bool] conditional behavior and NullBuilder semantics. |
| README.md | Documents the new “Conditional elements” feature with an example. |
| html5tagger/nullbuilder.py | Introduces NullBuilder implementation used for the no-op path. |
| html5tagger/builder.py | Implements bool handling in __getitem__ and wires in NullBuilder. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
The Python
withstatement cannot be made conditional due to syntax. This PR adds another overload for the[]operator with bool argument to act as such toggle. Usingdoc[True]does nothing and processing after it continues normally.doc[False]returns a NullBuilder that does absolutely nothing with anything done to it, in effect discarding further operations on the same statement andwithstatements with it.