Skip to content

Commit ff52bc0

Browse files
committed
WIP
1 parent 8ec9501 commit ff52bc0

7 files changed

Lines changed: 588 additions & 505 deletions

File tree

src/docstub-stubs/_docstrings.pyi

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ import lark.visitors
1212
import numpydoc.docscrape as npds
1313

1414
from ._analysis import PyImport, TypeMatcher
15-
from ._doctype import BlacklistedQualname, Expression, Token, TokenKind, parse_doctype
15+
from ._doctype import BlacklistedQualname, Expr, Term, TermKind, parse_doctype
1616
from ._report import ContextReporter, Stats
1717
from ._utils import escape_qualname
1818

1919
logger: logging.Logger
2020

21-
def update_qualnames(
22-
expr: Expression, *, _parents: tuple[Expression, ...] = ...
23-
) -> Generator[tuple[tuple[Expression, ...], Token], str]: ...
24-
def _find_one_token(tree: lark.Tree, *, name: str) -> lark.Token: ...
21+
def _update_qualnames(
22+
expr: Expr, *, _parents: tuple[Expr, ...] = ...
23+
) -> Generator[tuple[tuple[Expr, ...], Term], str]: ...
2524
@dataclass(frozen=True, slots=True, kw_only=True)
2625
class Annotation:
2726

@@ -52,6 +51,13 @@ def _uncombine_numpydoc_params(
5251
params: list[npds.Parameter],
5352
) -> Generator[npds.Parameter]: ...
5453
def _red_partial_underline(doctype: str, *, start: int, stop: int) -> str: ...
54+
def doctype_to_annotation(
55+
doctype: str,
56+
*,
57+
matcher: TypeMatcher | None = ...,
58+
reporter: ContextReporter | None = ...,
59+
stats: Stats | None = ...,
60+
) -> Annotation: ...
5561

5662
class DocstringAnnotations:
5763
docstring: str
@@ -62,13 +68,10 @@ class DocstringAnnotations:
6268
self,
6369
docstring: str,
6470
*,
65-
matcher: TypeMatcher,
71+
matcher: TypeMatcher | None = ...,
6672
reporter: ContextReporter | None = ...,
6773
stats: Stats | None = ...,
6874
) -> None: ...
69-
def _doctype_to_annotation(
70-
self, doctype: str, ds_line: int = ...
71-
) -> Annotation: ...
7275
@cached_property
7376
def attributes(self) -> dict[str, Annotation]: ...
7477
@cached_property

src/docstub-stubs/_doctype.pyi

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# File generated with docstub
2+
3+
import enum
4+
import keyword
5+
import logging
6+
from collections.abc import Generator, Iterable, Sequence
7+
from dataclasses import dataclass
8+
from pathlib import Path
9+
from textwrap import indent
10+
from typing import Any, Final
11+
12+
import lark
13+
import lark.visitors
14+
from _typeshed import Incomplete
15+
16+
from ._utils import DocstubError
17+
18+
logger: Final
19+
20+
grammar_path: Final
21+
22+
with grammar_path.open() as file:
23+
_grammar: Final
24+
25+
_lark: Final
26+
27+
def flatten_recursive(iterable: Iterable[Iterable | str]) -> Generator[str]: ...
28+
def insert_between(iterable: Iterable, *, sep: Any) -> list[Any]: ...
29+
30+
class TermKind(enum.StrEnum):
31+
32+
NAME = enum.auto()
33+
LITERAL = enum.auto()
34+
SYNTAX = enum.auto()
35+
36+
class Term(str):
37+
38+
__slots__: Final
39+
40+
def __new__(
41+
cls, value: str, *, kind: TermKind | str, pos: tuple[int, int] | None = ...
42+
) -> None: ...
43+
def __repr__(self) -> str: ...
44+
def __getnewargs_ex__(self) -> tuple[tuple[Any, ...], dict[str, Any]]: ...
45+
46+
@dataclass(slots=True)
47+
class Expr:
48+
49+
rule: str
50+
children: list[Expr | Term]
51+
52+
@property
53+
def terms(self) -> list[Term]: ...
54+
@property
55+
def names(self) -> list[Term]: ...
56+
def __iter__(self) -> Generator[Expr | Term]: ...
57+
def format_tree(self) -> str: ...
58+
def __repr__(self) -> str: ...
59+
def __str__(self) -> str: ...
60+
def as_code(self) -> str: ...
61+
62+
BLACKLISTED_QUALNAMES: Final
63+
64+
class BlacklistedQualname(DocstubError):
65+
pass
66+
67+
class DoctypeTransformer(lark.visitors.Transformer):
68+
def start(self, tree: lark.Tree) -> Expr: ...
69+
def qualname(self, tree: lark.Tree) -> Term: ...
70+
def ELLIPSES(self, token: lark.Token) -> Term: ...
71+
def union(self, tree: lark.Tree) -> Expr: ...
72+
def subscription(self, tree: lark.Tree) -> Expr: ...
73+
def natlang_literal(self, tree: lark.Tree) -> Expr: ...
74+
def literal_item(self, tree: lark.Tree) -> Term: ...
75+
def natlang_container(self, tree: lark.Tree) -> Expr: ...
76+
def natlang_array(self, tree: lark.Tree) -> Expr: ...
77+
def array_name(self, tree: lark.Tree) -> Term: ...
78+
def dtype(self, tree: lark.Tree) -> Expr: ...
79+
def shape(self, tree: lark.Tree) -> lark.visitors._DiscardType: ...
80+
def optional_info(self, tree: lark.Tree) -> lark.visitors._DiscardType: ...
81+
def extra_info(self, tree: lark.Tree) -> lark.visitors._DiscardType: ...
82+
def _format_subscription(
83+
self, sequence: Sequence[str], rule: str = ...
84+
) -> Expr: ...
85+
86+
_transformer: Final
87+
88+
def parse_doctype(doctype: str) -> Expr: ...

0 commit comments

Comments
 (0)