Conversation
This comment has been minimized.
This comment has been minimized.
|
Thanks, not a full review, yet, but stubtest noticed some differences between the stubs and the runtime: https://github.com/python/typeshed/actions/runs/24074408358/job/70219100854?pr=15623 This doesn't mean that stubtest is correct, but these errors should be looked at. In cases where you're sure that stubtest is wrong, add a file |
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
There was a problem hiding this comment.
Thanks, a few smaller suggestions below.
stubs/tinycss2/tinycss2/__init__.pyi
Outdated
| __version__: str = ... | ||
| VERSION: str = ... |
There was a problem hiding this comment.
| __version__: str = ... | |
| VERSION: str = ... | |
| __version__: Final[str] | |
| VERSION: Final[str] |
(Final needs import from typing.)
| def serialize(self) -> str: ... | ||
|
|
||
| class ParseError(Node): | ||
| type: Literal["error"] |
There was a problem hiding this comment.
It probably makes sense to use Final here (and in the type fields below) as well:
| type: Literal["error"] | |
| type: Final = "error" |
stubs/tinycss2/tinycss2/bytes.pyi
Outdated
| from .ast import Node | ||
|
|
||
| def decode_stylesheet_bytes( | ||
| css_bytes: bytes, protocol_encoding: str | None = ..., environment_encoding: Encoding | None = ... |
There was a problem hiding this comment.
We now generally add simple defaults to typeshed, instead of .... The latter is only used in complex cases:
| css_bytes: bytes, protocol_encoding: str | None = ..., environment_encoding: Encoding | None = ... | |
| css_bytes: bytes, protocol_encoding: str | None = None, environment_encoding: Encoding | None = None |
stubs/tinycss2/tinycss2/bytes.pyi
Outdated
| protocol_encoding: str | None = ..., | ||
| environment_encoding: Encoding | None = ..., | ||
| skip_comments: bool = ..., | ||
| skip_whitespace: bool = ..., |
There was a problem hiding this comment.
| protocol_encoding: str | None = ..., | |
| environment_encoding: Encoding | None = ..., | |
| skip_comments: bool = ..., | |
| skip_whitespace: bool = ..., | |
| protocol_encoding: str | None = None, | |
| environment_encoding: Encoding | None = None, | |
| skip_comments: bool = False, | |
| skip_whitespace: bool = False, |
stubs/tinycss2/tinycss2/color5.pyi
Outdated
| COLOR_SPACES: set[str] | None | ||
|
|
||
| def parse_color( | ||
| input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = ... |
There was a problem hiding this comment.
| input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = ... | |
| input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = None |
stubs/tinycss2/tinycss2/parser.pyi
Outdated
| def parse_one_component_value(input: str | Iterable[Node], skip_comments: bool = ...) -> Node: ... | ||
| def parse_one_declaration(input: str | Iterable[Node], skip_comments: bool = ...) -> Declaration | ParseError: ... | ||
| def parse_blocks_contents( | ||
| input: str | Iterable[Node], skip_comments: bool = ..., skip_whitespace: bool = ... | ||
| ) -> list[Declaration | AtRule | QualifiedRule | Comment | WhitespaceToken | ParseError]: ... | ||
| def parse_declaration_list( | ||
| input: str | Iterable[Node], skip_comments: bool = ..., skip_whitespace: bool = ... | ||
| ) -> list[Declaration | AtRule | Comment | WhitespaceToken | ParseError]: ... | ||
| def parse_one_rule(input: str | Iterable[Node], skip_comments: bool = ...) -> QualifiedRule | AtRule | ParseError: ... | ||
| def parse_rule_list(input: str | Iterable[Node], skip_comments: bool = ..., skip_whitespace: bool = ...) -> list[_Rule]: ... | ||
| def parse_stylesheet(input: str | Iterable[Node], skip_comments: bool = ..., skip_whitespace: bool = ...) -> list[_Rule]: ... |
There was a problem hiding this comment.
Defaults are missing here as well.
| @@ -0,0 +1,3 @@ | |||
| from .ast import Node | |||
|
|
|||
| def parse_component_value_list(css: str, skip_comments: bool = ...) -> list[Node]: ... | |||
There was a problem hiding this comment.
| def parse_component_value_list(css: str, skip_comments: bool = ...) -> list[Node]: ... | |
| def parse_component_value_list(css: str, skip_comments: bool = False) -> list[Node]: ... |
stubs/tinycss2/tinycss2/ast.pyi
Outdated
| def serialize(self) -> str: ... | ||
|
|
||
| class ParseError(Node): | ||
| __slots__ = str | Iterable[str] |
There was a problem hiding this comment.
For __slots__ you can include the runtime values:
__slots__ = ["kind", "message"]
stubs/tinycss2/METADATA.toml
Outdated
| @@ -0,0 +1,3 @@ | |||
| version = "1.5.1" | |||
| upstream_repository = "https://github.com/Kozea/tinycss2" | |||
There was a problem hiding this comment.
I have just merged a PR that changes field names to use dashes:
| upstream_repository = "https://github.com/Kozea/tinycss2" | |
| upstream-repository = "https://github.com/Kozea/tinycss2" |
|
Thanks for the reviews! Added the changes. Regarding |
This comment has been minimized.
This comment has been minimized.
|
Had to return the Literal back in ast.pyi because it won't type narrow with Final correctly otherwise in cases like: token: IdentToken | NumberToken
if token.type == "ident":
reveal_type(token) # IdentToken |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Hello!
Tinycss2 is completely untyped so here's everything in that lib.
First contribution, so might have made mistakes here and there.