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

HTMLParser.handle_starttag attrs incorrect type #3031

Closed
rgant opened this issue Jun 4, 2019 · 1 comment · Fixed by #3034
Closed

HTMLParser.handle_starttag attrs incorrect type #3031

rgant opened this issue Jun 4, 2019 · 1 comment · Fixed by #3034
Labels
stubs: false negative Type checkers do not report an error, but should

Comments

@rgant
Copy link
Contributor

rgant commented Jun 4, 2019

Attributes without a value will return None so the correct type should be:

    def handle_starttag(self, tag: str,
                        attrs: List[Tuple[str, Union[None, str]]]) -> None: ...

def handle_starttag(self, tag: str,

Example:

Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Python shell history and tab completion are enabled.
>>> from html.parser import HTMLParser
>>> class MyParser(HTMLParser):
...   def handle_starttag(self, tag, attrs):
...     print('%r' % attrs)
... 
>>> parser = MyParser()
>>> parser.feed('<input type="number" required>')
[('type', 'number'), ('required', None)]
@srittau srittau added size-small stubs: false negative Type checkers do not report an error, but should labels Jun 5, 2019
@srittau
Copy link
Collaborator

srittau commented Jun 5, 2019

Patches welcome! (Although it should preferable use Optional[str] instead of Union[None, str].)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false negative Type checkers do not report an error, but should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants