Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
fb0176b
Autogenerate stubs using scripts/create_baseline_stubs.py weasyprint
TuringTux Jan 31, 2026
f750a13
Start adding a few type hints for HTML
TuringTux Jan 31, 2026
427bbda
Upgrade stubs to latest versions
TuringTux Jul 13, 2026
0842b94
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
46f8cc3
Add further types
TuringTux Jul 13, 2026
bdaab60
Mark undocumented properties as undocumented
TuringTux Jul 13, 2026
0425f51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
88e9688
Annotate color_profiles
TuringTux Jul 13, 2026
213f456
Fix broken toml key
TuringTux Jul 13, 2026
86286e9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
931bd96
Add further annotations in __init__.pyi
TuringTux Jul 13, 2026
e15bfbb
Try inferring type of layer
TuringTux Jul 13, 2026
3da66c6
Add missing "| None"
TuringTux Jul 13, 2026
6d3440a
Guess type to be string
TuringTux Jul 13, 2026
4dfb333
Fix pre-commit check warnings for __init__.pyi
TuringTux Jul 13, 2026
190b8a6
Delete files which we won't need type annotations for
TuringTux Jul 13, 2026
dd8d51f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
1d953f4
Add FontConfiguration stub
TuringTux Jul 13, 2026
a32a507
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
7a85e56
Try adding dependencies
TuringTux Jul 13, 2026
1abc58d
Add two typehints for urls.py
TuringTux Jul 13, 2026
e0fb952
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
7c28b5a
Remove dependency which does not have any types provided
TuringTux Jul 13, 2026
a120724
Cheaply stub types for now
TuringTux Jul 13, 2026
27940ab
Consistently apply naming
TuringTux Jul 13, 2026
11a204d
Fix misreading error (it's not pypdf, its pydyf)
TuringTux Jul 13, 2026
8c41e38
Fix typo
TuringTux Jul 13, 2026
9aa6d4f
Use likely more accurate Reader type instead of underspecified IO type
TuringTux Jul 13, 2026
df0a682
Add types to dict
TuringTux Jul 13, 2026
97e8a13
Cheap out and just make the dicts all "Incomplete"
TuringTux Jul 13, 2026
12a7f32
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
582e91d
Revert "Use likely more accurate Reader type instead of underspecifie…
TuringTux Jul 13, 2026
bf75073
Add generic annotations
TuringTux Jul 13, 2026
b59e392
Avoid mentioning CounterName
TuringTux Jul 13, 2026
f844d02
Try avoiding generics altogether
TuringTux Jul 13, 2026
2d885d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
990134b
Revert "Delete files which we won't need type annotations for"
TuringTux Jul 13, 2026
9bfef82
Reformat file
TuringTux Jul 13, 2026
7604c81
Fix two more pydyf imports
TuringTux Jul 13, 2026
a2c23d3
Fix pipe character which didn't work here
TuringTux Jul 13, 2026
b356c2b
Try avoiding untyped decorator warnings
TuringTux Jul 13, 2026
59ae0d4
Comply with Y001
TuringTux Jul 13, 2026
1ca9ba9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
2b51569
Reformat file
TuringTux Jul 13, 2026
f196a51
Cheap out of completely annotating the decorators
TuringTux Jul 13, 2026
35d2001
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
82d2f76
Add minimally more decorator annotations
TuringTux Jul 13, 2026
48dc780
Annotate single_token better
TuringTux Jul 13, 2026
b4b670d
Annotate comma_separated_list better
TuringTux Jul 13, 2026
7fa626e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
ef51fd6
Annotate several collections
TuringTux Jul 13, 2026
90041c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2026
fb7c9af
Try cheating my way out of annotating
TuringTux Jul 14, 2026
b0e0995
Adjust exports
TuringTux Jul 14, 2026
69932c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 14, 2026
0488652
Mark _Options as type check only
TuringTux Jul 14, 2026
5a08e06
Merge remote-tracking branch 'upstream/main' into weasyprint
TuringTux Jul 14, 2026
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 pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"stubs/tensorflow",
"stubs/tqdm",
"stubs/vobject",
"stubs/weasyprint",
"stubs/workalendar",
"stubs/xmldiff",
],
Expand Down
2 changes: 2 additions & 0 deletions stubs/weasyprint/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "69.0.*"
upstream-repository = "https://github.com/Kozea/WeasyPrint"
Comment thread
TuringTux marked this conversation as resolved.
134 changes: 134 additions & 0 deletions stubs/weasyprint/weasyprint/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from _typeshed import Incomplete
from collections.abc import Callable
from datetime import datetime
from pathlib import Path
from typing import Any, BinaryIO, TextIO, TypeAlias, TypedDict, type_check_only
from typing_extensions import Unpack
from xml.etree.ElementTree import Element

from .css import ColorProfile
from .css.counters import CounterStyle
from .document import Document as Document, Page as Page
from .text.fonts import FontConfiguration
from .urls import URLFetcher, default_url_fetcher as default_url_fetcher

_ElementWrapper: TypeAlias = Any # actually csselect2.ElementWrapper
_Matcher: TypeAlias = Any # actually csselect2.Matcher
_PDF: TypeAlias = Any # actually pydyf.PDF

__all__ = ["CSS", "DEFAULT_OPTIONS", "HTML", "VERSION", "Attachment", "Document", "Page", "__version__", "default_url_fetcher"]

VERSION: str
__version__: str
DEFAULT_OPTIONS: _Options

@type_check_only
class _Options(TypedDict):
stylesheets: Incomplete
attachments: Incomplete
attachment_relationships: Incomplete
pdf_identifier: Incomplete
pdf_variant: Incomplete
pdf_version: Incomplete
pdf_forms: Incomplete
pdf_tags: Incomplete
uncompressed_pdf: Incomplete
xmp_metadata: Incomplete
custom_metadata: Incomplete
presentational_hints: Incomplete
output_intent: Incomplete
optimize_images: Incomplete
jpeg_quality: Incomplete
dpi: Incomplete
full_fonts: Incomplete
hinting: Incomplete
cache: Incomplete

_Selector: TypeAlias = tuple[Incomplete, str | None, Incomplete]
_PageRule: TypeAlias = tuple[Incomplete, list[_Selector], Incomplete]

class HTML:
base_url: str | Path | None # undocumented
url_fetcher: URLFetcher # undocumented
media_type: str # undocumented
wrapper_element: _ElementWrapper # undocumented
etree_element: Element # undocumented
def __init__(
self,
guess: str | Path | TextIO | BinaryIO | None = None,
filename: str | Path | None = None,
url: str | None = None,
file_obj: TextIO | BinaryIO | None = None,
string: str | None = None,
encoding: str | None = None,
base_url: str | Path | None = None,
url_fetcher: URLFetcher | None = None,
media_type: str = "print",
) -> None: ...
def render(
self,
font_config: FontConfiguration | None = None,
counter_style: CounterStyle | None = None,
color_profiles: dict[str, ColorProfile] | None = None,
**options: Unpack[_Options],
) -> Document: ...
def write_pdf(
self,
target: str | Path | TextIO | BinaryIO | None = None,
zoom: float = 1,
finisher: Callable[[Document, _PDF], Any] | None = None,
font_config: FontConfiguration | None = None,
counter_style: CounterStyle | None = None,
color_profiles: dict[str, ColorProfile] | None = None,
**options: Unpack[_Options],
) -> bytes | None: ...

class CSS:
base_url: str | Path | None # undocumented
matcher: _Matcher # undocumented
page_rules: list[_PageRule] # undocumented
layers: list[str] # undocumented
def __init__(
self,
guess: str | Path | TextIO | BinaryIO | None = None,
filename: str | Path | None = None,
url: str | None = None,
file_obj: TextIO | BinaryIO | None = None,
string: str | None = None,
encoding: str | None = None,
base_url: str | Path | None = None,
url_fetcher: URLFetcher | None = None,
_check_mime_type: bool = False,
media_type: str = "print",
font_config: FontConfiguration | None = None,
counter_style: CounterStyle | None = None,
color_profiles: dict[str, ColorProfile] | None = None,
matcher: _Matcher | None = None,
page_rules: list[_PageRule] | None = None,
layers: list[str] | None = None,
layer: str | None = None,
) -> None: ...

class Attachment:
source: tuple[TextIO | BinaryIO, str, str | None, str | None] # undocumented
name: str | None # undocumented
description: str | None # undocumented
relationship: str # undocumented
md5: Incomplete # undocumented
created: datetime # undocumented
modified: datetime # undocumented
def __init__(
self,
guess: str | Path | TextIO | BinaryIO | None = None,
filename: str | Path | None = None,
url: str | None = None,
file_obj: TextIO | BinaryIO | None = None,
string: str | None = None,
base_url: str | Path | None = None,
url_fetcher: URLFetcher | None = None,
name: str | None = None,
description: str | None = None,
created: datetime | None = None,
modified: datetime | None = None,
relationship: str = "Unspecified",
) -> None: ...
3 changes: 3 additions & 0 deletions stubs/weasyprint/weasyprint/anchors.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def rectangle_aabb(matrix, pos_x, pos_y, width, height): ...
def gather_anchors(box, anchors, links, bookmarks, forms, parent_matrix=None, parent_form=None) -> None: ...
def make_page_bookmark_tree(page, skipped_levels, last_by_depth, previous_level, page_number, matrix): ...
111 changes: 111 additions & 0 deletions stubs/weasyprint/weasyprint/css/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import NamedTuple

PSEUDO_ELEMENTS: Incomplete

class PageSelectorType(NamedTuple):
side: Incomplete
blank: Incomplete
first: Incomplete
index: Incomplete
name: Incomplete

class StyleFor:
initial_page_sizes: Incomplete
font_config: Incomplete
def __init__(self, html, sheets, presentational_hints, font_config, target_collector) -> None: ...
def __call__(self, element, pseudo_type=None): ...
def set_computed_styles(self, element, parent, root=None, pseudo_type=None, base_url=None, target_collector=None) -> None: ...
def add_page_declarations(self, page_type) -> None: ...
def get_cascaded_styles(self): ...
def get_computed_styles(self): ...

def get_child_text(element): ...
def text_decoration(key, value, parent_value, cascaded): ...
def find_stylesheets(
wrapper_element, device_media_type, url_fetcher, base_url, font_config, counter_style, color_profiles, page_rules, layers
) -> Generator[Incomplete]: ...
def find_style_attributes(tree, presentational_hints: bool = False, base_url=None) -> Generator[Incomplete, None, Incomplete]: ...
def declaration_precedence(origin, importance): ...
def resolve_var(computed, token, parent_style): ...
def resolve_math(token, computed=None, property_name=None, refer_to=None): ...

class InitialStyle(dict[Incomplete, Incomplete]):
parent_style: Incomplete
specified: Incomplete
cache: Incomplete
font_config: Incomplete
def __init__(self, font_config) -> None: ...
def __missing__(self, key): ...

class AnonymousStyle(dict[Incomplete, Incomplete]):
parent_style: Incomplete
is_root_element: bool
specified: Incomplete
cache: Incomplete
font_config: Incomplete
def __init__(self, parent_style) -> None: ...
def copy(self): ...
def __missing__(self, key): ...

class ComputedStyle(dict[Incomplete, Incomplete]):
specified: Incomplete
parent_style: Incomplete
cascaded: Incomplete
is_root_element: Incomplete
element: Incomplete
pseudo_type: Incomplete
root_style: Incomplete
base_url: Incomplete
font_config: Incomplete
initial_page_sizes: Incomplete
cache: Incomplete
def __init__(
self, parent_style, cascaded, element, pseudo_type, root_style, base_url, font_config, initial_page_sizes
) -> None: ...
def copy(self): ...
def __missing__(self, key): ...

class ColorProfile:
src: Incomplete
rendering_intent: Incomplete
components: Incomplete
pdf_reference: Incomplete
def __init__(self, file_object, src, rendering_intent, components) -> None: ...
@property
def name(self): ...
@property
def content(self): ...

def computed_from_cascaded(
element, cascaded, parent_style, pseudo_type=None, root_style=None, base_url=None, target_collector=None
): ...
def parse_color_profile_name(prelude): ...
def parse_page_selectors(rule): ...
def preprocess_stylesheet(
device_media_type,
base_url,
stylesheet_rules,
url_fetcher,
matcher,
page_rules,
layers,
font_config,
counter_style,
color_profiles,
ignore_imports: bool = False,
layer=None,
): ...
def get_all_computed_styles(
html,
user_stylesheets=None,
presentational_hints: bool = False,
font_config=None,
counter_style=None,
color_profiles=None,
page_rules=None,
layers=None,
target_collector=None,
forms: bool = False,
): ...
55 changes: 55 additions & 0 deletions stubs/weasyprint/weasyprint/css/computed_values.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from _typeshed import Incomplete

FONT_SIZE_KEYWORDS: Incomplete
BORDER_WIDTH_KEYWORDS: Incomplete
FONT_WEIGHT_RELATIVE: Incomplete
PAGE_SIZES: Incomplete
INITIAL_PAGE_SIZE: Incomplete
PHYSICAL_FUNCTIONS: Incomplete

def register_logical(names, prefixes=("",), suffixes=("",)): ...
def physical_size(name, prefix, suffix, block, inline): ...
def physical_inset(name, prefix, suffix, block, inline): ...
def physical_radius(name, prefix, suffix, block, inline): ...

COMPUTER_FUNCTIONS: Incomplete

def register_computer(name): ...
def compute_attr(style, values): ...
def background_image(style, name, values): ...
def image(style, name, image): ...
def color(style, name, values): ...
def compute_position(style, name, values): ...
def length_or_percentage_tuple(style, name, values): ...
def length_tuple(style, name, values): ...
def break_before_after(style, name, value): ...
def length(style, name, value, font_size=None, pixels_only: bool = False): ...
def bleed(style, name, value): ...
def pixel_length(style, name, value): ...
def background_size(style, name, values): ...
def image_orientation(style, name, values): ...
def border_width(style, name, value): ...
def border_image_slice(style, name, values): ...
def border_image_width(style, name, values): ...
def border_image_outset(style, name, values): ...
def border_image_repeat(style, name, values): ...
def length_pixels_only(style, name, value): ...
def border_radius(style, name, values): ...
def gap(style, name, value): ...
def bookmark_label(style, name, values): ...
def string_set(style, name, values): ...
def content(style, name, values): ...
def display(style, name, value): ...
def compute_float(style, name, value): ...
def font_size(style, name, value): ...
def font_weight(style, name, value): ...
def grid_template(style, name, values): ...
def grid_auto(style, name, values): ...
def line_height(style, name, value): ...
def anchor(style, name, values): ...
def link(style, name, values): ...
def lang(style, name, values): ...
def tab_size(style, name, value): ...
def transform(style, name, value): ...
def vertical_align(style, name, value): ...
def word_spacing(style, name, value): ...
10 changes: 10 additions & 0 deletions stubs/weasyprint/weasyprint/css/counters.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from _typeshed import Incomplete

def symbol(string_or_url) -> str: ...
def parse_counter_style_name(tokens, counter_style): ...

class CounterStyle(dict[Incomplete, Incomplete]):
def resolve_counter(self, counter_name, previous_types=None): ...
def render_value(self, counter_value, counter_name=None, counter=None, previous_types=None): ...
def render_marker(self, counter_name, counter_value): ...
def copy(self) -> CounterStyle: ...
15 changes: 15 additions & 0 deletions stubs/weasyprint/weasyprint/css/functions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from _typeshed import Incomplete

class Function:
name: Incomplete
arguments: Incomplete
def __init__(self, token) -> None: ...
def split_space(self): ...
def split_comma(self, single_tokens: bool = True, trailing: bool = False): ...

def check_attr(token, allowed_type=None): ...
def check_counter(token, allowed_type=None): ...
def check_content(token): ...
def check_string_or_element(string_or_element, token): ...
def check_var(token): ...
def check_math(token): ...
2 changes: 2 additions & 0 deletions stubs/weasyprint/weasyprint/css/media_queries.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def evaluate_media_query(query_list, device_media_type): ...
def parse_media_query(tokens): ...
13 changes: 13 additions & 0 deletions stubs/weasyprint/weasyprint/css/properties.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from _typeshed import Incomplete
from typing import NamedTuple

class Dimension(NamedTuple):
value: Incomplete
unit: Incomplete

ZERO_PIXELS: Incomplete
INITIAL_VALUES: Incomplete
KNOWN_PROPERTIES: Incomplete
INHERITED: Incomplete
TABLE_WRAPPER_BOX_PROPERTIES: Incomplete
INITIAL_NOT_COMPUTED: Incomplete
35 changes: 35 additions & 0 deletions stubs/weasyprint/weasyprint/css/targets.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from _typeshed import Incomplete

class TargetLookupItem:
state: Incomplete
target_box: Incomplete
parse_again_functions: Incomplete
page_maker_index: Incomplete
cached_page_counter_values: Incomplete
def __init__(self, state: str = "pending") -> None: ...

class CounterLookupItem:
parse_again: Incomplete
missing_counters: Incomplete
missing_target_counters: Incomplete
page_maker_index: Incomplete
pending: bool
cached_page_counter_values: Incomplete
def __init__(self, parse_again, missing_counters, missing_target_counters) -> None: ...

def anchor_name_from_token(anchor_token): ...

class TargetCollector:
target_lookup_items: Incomplete
counter_lookup_items: Incomplete
collecting: bool
had_pending_targets: bool
def __init__(self) -> None: ...
def collect_anchor(self, anchor_name) -> None: ...
def lookup_target(self, anchor_token, source_box, css_token, parse_again): ...
def store_target(self, anchor_name, target_counter_values, target_box) -> None: ...
def collect_missing_counters(
self, parent_box, css_token, parse_again_function, missing_counters, missing_target_counters
) -> None: ...
def check_pending_targets(self) -> None: ...
def cache_target_page_counters(self, anchor_name, page_counter_values, page_maker_index, page_maker) -> None: ...
Loading
Loading