Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions stubs/tinycss2/tinycss2/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ from .serializer import serialize as serialize, serialize_identifier as serializ
from .tokenizer import parse_component_value_list as parse_component_value_list

__version__: str = ...
VERSION: str = ...
48 changes: 23 additions & 25 deletions stubs/tinycss2/tinycss2/ast.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from collections.abc import Iterable
from typing import Literal

class Node:
__slots__ = str | Iterable[str]
source_line: int
source_column: int
type: str
Expand All @@ -11,152 +9,152 @@ class Node:
def serialize(self) -> str: ...

class ParseError(Node):
__slots__ = str | Iterable[str]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For __slots__ you can include the runtime values:

__slots__ = ["kind", "message"]

type: Literal["error"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It probably makes sense to use Final here (and in the type fields below) as well:

Suggested change
type: Literal["error"]
type: Final = "error"

kind: str
message: str
repr_format: str
def __init__(self, line: int, column: int, kind: str, message: str) -> None: ...

class Comment(Node):
__slots__ = str | Iterable[str]
type: Literal["comment"]
value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

class WhitespaceToken(Node):
__slots__ = str | Iterable[str]
type: Literal["whitespace"]
value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

class LiteralToken(Node):
__slots__ = str | Iterable[str]
type: Literal["literal"]
value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

class IdentToken(Node):
__slots__ = str | Iterable[str]
type: Literal["ident"]
value: str
lower_value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

class AtKeywordToken(Node):
__slots__ = str | Iterable[str]
type: Literal["at-keyword"]
value: str
lower_value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

class HashToken(Node):
__slots__ = str | Iterable[str]
type: Literal["hash"]
value: str
is_identifier: bool
repr_format: str
def __init__(self, line: int, column: int, value: str, is_identifier: bool) -> None: ...

class StringToken(Node):
__slots__ = str | Iterable[str]
type: Literal["string"]
value: str
representation: str
repr_format: str
def __init__(self, line: int, column: int, value: str, representation: str) -> None: ...

class URLToken(Node):
__slots__ = str | Iterable[str]
type: Literal["url"]
value: str
representation: str
repr_format: str
def __init__(self, line: int, column: int, value: str, representation: str) -> None: ...

class UnicodeRangeToken(Node):
__slots__ = str | Iterable[str]
type: Literal["unicode-range"]
start: int
end: int
repr_format: str
def __init__(self, line: int, column: int, start: int, end: int) -> None: ...

class NumberToken(Node):
__slots__ = str | Iterable[str]
type: Literal["number"]
value: float
int_value: int | None
is_integer: bool
representation: str
repr_format: str
def __init__(self, line: int, column: int, value: float, int_value: int | None, representation: str) -> None: ...

class PercentageToken(Node):
__slots__ = str | Iterable[str]
type: Literal["percentage"]
value: float
int_value: int | None
is_integer: bool
representation: str
repr_format: str
def __init__(self, line: int, column: int, value: float, int_value: int | None, representation: str) -> None: ...

class DimensionToken(Node):
__slots__ = str | Iterable[str]
type: Literal["dimension"]
value: float
int_value: int | None
is_integer: bool
representation: str
unit: str
lower_unit: str
repr_format: str
def __init__(self, line: int, column: int, value: float, int_value: int | None, representation: str, unit: str) -> None: ...

class ParenthesesBlock(Node):
__slots__ = str | Iterable[str]
type: Literal["()"]
type: Literal["() block"]
content: list[Node]
repr_format: str
def __init__(self, line: int, column: int, content: list[Node]) -> None: ...

class SquareBracketsBlock(Node):
__slots__ = str | Iterable[str]
type: Literal["[]"]
type: Literal["[] block"]
content: list[Node]
repr_format: str
def __init__(self, line: int, column: int, content: list[Node]) -> None: ...

class CurlyBracketsBlock(Node):
__slots__ = str | Iterable[str]
type: Literal["{}"]
type: Literal["{} block"]
content: list[Node]
repr_format: str
def __init__(self, line: int, column: int, content: list[Node]) -> None: ...

class FunctionBlock(Node):
__slots__ = str | Iterable[str]
type: Literal["function"]
name: str
lower_name: str
arguments: list[Node]
repr_format: str
def __init__(self, line: int, column: int, name: str, arguments: list[Node]) -> None: ...

class Declaration(Node):
__slots__ = str | Iterable[str]
type: Literal["declaration"]
name: str
lower_name: str
value: list[Node]
important: bool
repr_format: str
def __init__(self, line: int, column: int, name: str, lower_name: str, value: list[Node], important: bool) -> None: ...

class QualifiedRule(Node):
__slots__ = str | Iterable[str]
type: Literal["qualified-rule"]
prelude: list[Node]
content: list[Node]
repr_format: str
def __init__(self, line: int, column: int, prelude: list[Node], content: list[Node]) -> None: ...

class AtRule(Node):
__slots__ = str | Iterable[str]
type: Literal["at-rule"]
at_keyword: str
lower_at_keyword: str
prelude: list[Node]
content: list[Node] | None
repr_format: str
def __init__(
self, line: int, column: int, at_keyword: str, lower_at_keyword: str, prelude: list[Node], content: list[Node] | None
) -> None: ...
6 changes: 5 additions & 1 deletion stubs/tinycss2/tinycss2/color4.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import Literal
from .ast import Node

class Color:
COLOR_SPACES: set[str]
COLOR_SPACES: set[str] | None
def __init__(self, space: str, coordinates: tuple[float | None, ...], alpha: float) -> None: ...
def __iter__(self) -> Iterator[float | None]: ...
def __getitem__(self, key: int) -> float: ...
Expand All @@ -13,3 +13,7 @@ class Color:
def to(self, space: str) -> Color: ...

def parse_color(input: str | Iterable[Node]) -> Color | Literal["currentcolor"] | None: ...

COLOR_SPACES: set[str]
D50: tuple[float, float, float]
D65: tuple[float, float, float]
9 changes: 7 additions & 2 deletions stubs/tinycss2/tinycss2/color5.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ from typing import Literal
from . import color4
from .ast import Node

COLOR_SCHEMES: set[str]
COLOR_SPACES: set[str]
D50: tuple[float, float, float]
D65: tuple[float, float, float]

class Color(color4.Color):
COLOR_SPACES: set[str]
COLOR_SPACES: set[str] | None

def parse_color(
input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] = ...
input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = ...
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = ...
input: str | Iterable[Node], color_schemes: Literal["normal"] | Iterable[str] | None = None

) -> color4.Color | Color | Literal["currentcolor"] | None: ...
3 changes: 3 additions & 0 deletions stubs/tinycss2/tinycss2/nth.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from collections.abc import Iterable
from re import Pattern

from .ast import Node

def parse_nth(input: str | Iterable[Node]) -> tuple[int, int] | None: ...
def parse_b(tokens: Iterable[Node], a: int) -> tuple[int, int] | None: ...
def parse_signless_b(tokens: Iterable[Node], a: int, b_sign: int) -> tuple[int, int] | None: ...
def parse_end(tokens: Iterable[Node], a: int, b: int) -> tuple[int, int] | None: ...

N_DASH_DIGITS_RE: Pattern[str]
6 changes: 3 additions & 3 deletions stubs/tinycss2/tinycss2/parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import TypeAlias

from .ast import AtRule, Comment, Declaration, Node, ParseError, QualifiedRule, WhitespaceToken

Rule: TypeAlias = QualifiedRule | AtRule | Comment | WhitespaceToken | ParseError
_Rule: TypeAlias = QualifiedRule | AtRule | Comment | WhitespaceToken | ParseError

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: ...
Expand All @@ -14,5 +14,5 @@ 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]: ...
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]: ...
2 changes: 2 additions & 0 deletions stubs/tinycss2/tinycss2/serializer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ def serialize_identifier(value: str) -> str: ...
def serialize_name(value: str) -> str: ...
def serialize_string_value(value: str) -> str: ...
def serialize_url(value: str) -> str: ...

BAD_PAIRS: set[tuple[str, str]]