Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions stubs/tinycss2/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "1.5.1"
upstream_repository = "https://github.com/Kozea/tinycss2"
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.

I have just merged a PR that changes field names to use dashes:

Suggested change
upstream_repository = "https://github.com/Kozea/tinycss2"
upstream-repository = "https://github.com/Kozea/tinycss2"

dependencies = ["types-webencodings"]
15 changes: 15 additions & 0 deletions stubs/tinycss2/tinycss2/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .bytes import parse_stylesheet_bytes as parse_stylesheet_bytes
from .parser import (
parse_blocks_contents as parse_blocks_contents,
parse_declaration_list as parse_declaration_list,
parse_one_component_value as parse_one_component_value,
parse_one_declaration as parse_one_declaration,
parse_one_rule as parse_one_rule,
parse_rule_list as parse_rule_list,
parse_stylesheet as parse_stylesheet,
)
from .serializer import serialize as serialize, serialize_identifier as serialize_identifier
from .tokenizer import parse_component_value_list as parse_component_value_list

__version__: str = ...
VERSION: 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.

Suggested change
__version__: str = ...
VERSION: str = ...
__version__: Final[str]
VERSION: Final[str]

(Final needs import from typing.)

160 changes: 160 additions & 0 deletions stubs/tinycss2/tinycss2/ast.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from typing import Literal

class Node:
source_line: int
source_column: int
type: str

def __init__(self, source_line: int, source_column: int) -> None: ...
def serialize(self) -> str: ...

class ParseError(Node):
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):
type: Literal["comment"]
value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

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

class LiteralToken(Node):
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):
type: Literal["ident"]
value: str
lower_value: str
repr_format: str
def __init__(self, line: int, column: int, value: str) -> None: ...

class AtKeywordToken(Node):
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):
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):
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):
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):
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):
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):
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):
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):
type: Literal["() block"]
content: list[Node]
repr_format: str
def __init__(self, line: int, column: int, content: list[Node]) -> None: ...

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

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

class FunctionBlock(Node):
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):
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):
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):
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: ...
14 changes: 14 additions & 0 deletions stubs/tinycss2/tinycss2/bytes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from webencodings import Encoding

from .ast import Node

def decode_stylesheet_bytes(
css_bytes: bytes, protocol_encoding: str | None = ..., environment_encoding: Encoding | 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.

We now generally add simple defaults to typeshed, instead of .... The latter is only used in complex cases:

Suggested change
css_bytes: bytes, protocol_encoding: str | None = ..., environment_encoding: Encoding | None = ...
css_bytes: bytes, protocol_encoding: str | None = None, environment_encoding: Encoding | None = None

) -> tuple[str, Encoding]: ...
def parse_stylesheet_bytes(
css_bytes: bytes,
protocol_encoding: str | None = ...,
environment_encoding: Encoding | None = ...,
skip_comments: bool = ...,
skip_whitespace: bool = ...,
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
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,

) -> tuple[list[Node], Encoding]: ...
12 changes: 12 additions & 0 deletions stubs/tinycss2/tinycss2/color3.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from collections.abc import Iterable
from typing import NamedTuple

from .ast import Node

class RGBA(NamedTuple):
red: float
green: float
blue: float
alpha: float

def parse_color(input: str | Iterable[Node]) -> str | RGBA | None: ...
19 changes: 19 additions & 0 deletions stubs/tinycss2/tinycss2/color4.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from collections.abc import Iterable, Iterator
from typing import Literal

from .ast import Node

class Color:
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: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
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]
17 changes: 17 additions & 0 deletions stubs/tinycss2/tinycss2/color5.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections.abc import Iterable
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] | None

def parse_color(
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: ...
11 changes: 11 additions & 0 deletions stubs/tinycss2/tinycss2/nth.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +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]
18 changes: 18 additions & 0 deletions stubs/tinycss2/tinycss2/parser.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from collections.abc import Iterable
from typing import TypeAlias

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

_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: ...
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]: ...
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.

Defaults are missing here as well.

11 changes: 11 additions & 0 deletions stubs/tinycss2/tinycss2/serializer.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from collections.abc import Iterable

from .ast import Node

def serialize(nodes: Iterable[Node]) -> str: ...
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]]
3 changes: 3 additions & 0 deletions stubs/tinycss2/tinycss2/tokenizer.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .ast import Node

def parse_component_value_list(css: str, skip_comments: bool = ...) -> list[Node]: ...
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
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]: ...