-
Notifications
You must be signed in to change notification settings - Fork 7
Stop introspecting rawdata after Python 3.14.7 internal buffering added. #168
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
Open
ianjosephwilson
wants to merge
2
commits into
t-strings:main
Choose a base branch
from
ianjosephwilson:ian/stop_introspecting_rawdata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -504,24 +504,11 @@ def reset(self): | |
| self.sinfo_table = {} | ||
|
|
||
| def close(self) -> None: | ||
| if self.waiting_for_data(): | ||
| # We apply heuristics here to try to guess why the parser didn't finish. | ||
| if self.rawdata.count('"') % 2 == 1 or self.rawdata.count("'") % 2 == 1: | ||
| raise ValueError( | ||
| "Parser expects more data, maybe you left an attribute quote unclosed?" | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| "Parser expects more data, is the template valid html?" | ||
| ) | ||
| super().close() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An internal flush has to be forced here so
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| if self.stack: | ||
| raise ValueError("Invalid HTML structure: unclosed tags remain.") | ||
| if self.source and self.source.has_placeholders(): | ||
| raise ValueError("Some placeholders were never resolved.") | ||
| super().close() | ||
|
|
||
| def waiting_for_data(self): | ||
| return len(self.rawdata) > 0 | ||
|
|
||
| # ------------------------------------------ | ||
| # Getting the parsed node tree | ||
|
|
||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind losing this.
That said, if we wanted to restore this behavior, I suppose we could:
feed()exactly once, and remember its lengthclose(), callgetpos()and see if there's still a bit of content leftThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result is pretty confusing, especially something like
html(t'''<div id='1"></div>''') == ''.It also breaks our placeholder tracking. Kind of a bummer. Maybe it won't happen very often because most people will be using an editor that will highlight the asymmetry of the quotes. I think the fact we are parsing small fragments is a disadvantage in this situation though because it exacerbates this type of mistake. This catches that we didn't use the placeholder but the user probably doesn't understand why:
html(t'''<div id='{True}">''')raisesValueError: Some placeholders were never resolved..A short test of your idea and it seems to work(!) but we are still implicitly depending on the implementation because we assume the buffering doesn't take place until after the first feed. We know that... because it says so in the source! Although if the threshold was higher then it might not parse at all. Seems like a really big implementation change on the stdlib's part which makes me nervous. Maybe this will just have to be a "gotcha" for a while...
I wonder where a good place to bring this up would be, a feature request on the issue tracker seems like it would get put on ice forever. Maybe starting a discussion on discuss.python.org? I'm an optimist on Thursdays.