Skip to content

Commit a27715a

Browse files
committed
WIP
1 parent ff52bc0 commit a27715a

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

src/docstub/_doctype.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Parsing of doctypes."""
22

33
import enum
4-
import logging
54
import keyword
5+
import logging
66
from collections.abc import Iterable
77
from dataclasses import dataclass
88
from pathlib import Path
@@ -14,7 +14,6 @@
1414

1515
from ._utils import DocstubError
1616

17-
1817
logger: Final = logging.getLogger(__name__)
1918

2019

@@ -25,7 +24,7 @@
2524

2625
# TODO try passing `transformer=DoctypeTransformer()`, may be faster [1]
2726
# [1] https://lark-parser.readthedocs.io/en/latest/classes.html#:~:text=after%20the%20parse%2C-,but%20faster,-)
28-
_lark: Final = lark.Lark(_grammar, propagate_positions=True, parser="lalr")
27+
_lark: Final = lark.Lark(_grammar, propagate_positions=True)
2928

3029

3130
def flatten_recursive(iterable):
@@ -83,7 +82,7 @@ class Term(str):
8382
__slots__ : Final
8483
"""
8584

86-
__slots__ = ("value", "kind", "pos")
85+
__slots__ = ("kind", "pos", "value")
8786

8887
def __new__(cls, value, *, kind, pos=None):
8988
"""

tests/test_doctype.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22

3-
import pytest
43
import lark
54
import lark.exceptions
5+
import pytest
66

7-
from docstub._doctype import parse_doctype, Term, TermKind, BLACKLISTED_QUALNAMES
7+
from docstub._doctype import BLACKLISTED_QUALNAMES, parse_doctype
88

99

1010
class Test_parse_doctype:
@@ -212,14 +212,8 @@ def test_rst_role(self, doctype, expected):
212212
["(2, 3)", "(N, m)", "3D", "2-D", "(N, ...)", "([P,] M, N)"]
213213
)
214214
def test_natlang_array(self, fmt, expected_fmt, name, dtype, shape):
215-
216-
def escape(name: str) -> str:
217-
return name.replace("-", "_").replace(".", "_")
218-
219215
doctype = fmt.format(name=name, dtype=dtype, shape=shape)
220-
expected = expected_fmt.format(
221-
name=escape(name), dtype=escape(dtype), shape=shape
222-
)
216+
expected = expected_fmt.format(name=name, dtype=dtype, shape=shape)
223217
expr = parse_doctype(doctype)
224218
assert expr.as_code() == expected
225219
# fmt: on
@@ -267,4 +261,3 @@ def test_multiple_unknown_names(self):
267261
PyImport(import_="Incomplete", from_="_typeshed", as_="c"),
268262
}
269263
assert unknown_names == [("a.b", 0, 3), ("c", 7, 8)]
270-

0 commit comments

Comments
 (0)