-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Additions to the html5lib stubs to handle type safety warnings in Beautiful Soup's html5lib code. #11411
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
Additions to the html5lib stubs to handle type safety warnings in Beautiful Soup's html5lib code. #11411
Conversation
| def reset(self) -> None: ... | ||
| def openStream(self, source): ... | ||
| def position(self): ... | ||
| def position(self) -> tuple[int, int]: ... |
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.
| lastPhase: Any | ||
| beforeRCDataPhase: Any | ||
| framesetOK: bool | ||
| tokenizer: Any |
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.
This is set by HTMLParser._parse, not by the constructor, so it's not always guaranteed to be there, but the same is true of lastPhase, beforeRCDataPhase, framesetOK, and so on.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
JelleZijlstra
left a comment
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.
Thanks! I'll look into the other issue you mentioned in your description.
I think the stub is actually right. The parse method (not to be confused with the separate module-level function named |
I started out investigating comments in python#11411 and ended up adding a few other types that were reasonably obvious from the source code. For reference: https://github.com/html5lib/html5lib-python/tree/master/html5lib cc @leonardr
This makes sense, thanks for the explanation. |
I started out investigating comments in #11411 and ended up adding a few other types that were reasonably obvious from the source code. For reference: https://github.com/html5lib/html5lib-python/tree/master/html5lib
I'm adding type hints to my project Beautiful Soup, and part of this work required minor changes to the typeshed stubs for html5lib. This PR contributes those changes back to typeshed.
I've also noticed that the typeshed stub for
HTMLParser.parse()is wrong: it lists the second argument asscripting:bool, but the second argument is actuallytreebuilder:str;scriptingis one of the keyword arguments. But I'm too new to Python type hints to know what should be done withscripting, and I also don't know what downstream effects a change might have on other users, so I'm not trying to fix that in this branch.