Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stubs/html5lib/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version = "1.1.*"
upstream_repository = "https://github.com/html5lib/html5lib-python"

requires = ["six"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use types for six, you need to add types-six since the types are distributed separately:

Suggested change
requires = ["six"]
requires = ["types-six"]


[tool.stubtest]
extras = ["all"]
11 changes: 6 additions & 5 deletions stubs/html5lib/html5lib/serializer.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import overload

from six import text_type

Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below

Suggested change
from six import text_type

k: str
v: str | int

Expand Down Expand Up @@ -32,11 +33,11 @@ class HTMLSerializer:
errors: Incomplete
strict: bool
def __init__(self, **kwargs) -> None: ...
def encode(self, string): ...
def encodeStrict(self, string): ...
def encode(self, string: text_type) -> str: ...
def encodeStrict(self, string: text_type) -> str: ...
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since you are only using text_type (adding types-six specifically), this doesn't make sense, since text_type is just an alias for str.
Also, both methods could return bytes if self.encoding is set:

Suggested change
def encode(self, string: text_type) -> str: ...
def encodeStrict(self, string: text_type) -> str: ...
def encode(self, string: str) -> str | bytes: ...
def encodeStrict(self, string: str) -> str | bytes: ...

encoding: Incomplete
def serialize(self, treewalker, encoding=None) -> Generator[Incomplete]: ...
def render(self, treewalker, encoding=None): ...
def serialize(self, treewalker: str, encoding: str) -> str: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Indeed, encoding could accept str, but it is an optional argument (this is what causes problems with CI passing).
  2. treewalker looks like some Iterable of dictionaries (i'd call it _Token), but since we don't have _Token TypedDict yet, I suggest using Iterable[dict[str, Incomplete]]
  3. serialize doesn't just return a string, it yields it, and since with the encoding set, it can be bytes. I think you can use Iterator or Generator
Suggested change
def serialize(self, treewalker: str, encoding: str) -> str: ...
def serialize(self, treewalker: Iterable[dict[str, Incomplete]], encoding: str | None = None) -> Iterator[str | bytes]: ...

def render(self, treewalker: str, encoding: str) -> str: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (except return type)
But I suggest you use overload here to differentiate between cases where str is returned and cases where bytes is returned

Suggested change
def render(self, treewalker: str, encoding: str) -> str: ...
@overload
def render(self, treewalker: Iterable[dict[str, Incomplete]], encoding: Literal[""] | None = None) -> bytes: ...
@overload
def render(self, treewalker: Iterable[dict[str, Incomplete]], encoding: str) -> str: ...

def serializeError(self, data: str = "XXX ERROR MESSAGE NEEDED") -> None: ...

class SerializeError(Exception): ...
Loading