Skip to content

Commit f278454

Browse files
committed
Added some TODOs
1 parent cde0b58 commit f278454

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/parsy/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
# Parser[str] is a subtype of Parser[Union[str, int]]
2121
# Result[str] is a subtype of Result[Union[str, int]]
22-
# So we want covariance for these
22+
# So we want covariance for these.
23+
24+
# However, that gives me problems with any methods that use these type vars.
2325

2426
OUT = TypeVar("OUT")
2527
OUT1 = TypeVar("OUT1")
@@ -428,6 +430,14 @@ def regex_parser(stream, index):
428430
return regex_parser
429431

430432

433+
# TODO the rest of the functions here need type annotations.
434+
435+
# One problem is that `test_item` and `match_item` are assumning that the input
436+
# type might not be str, but arbitrary types, including heterogeneous
437+
# lists. We have no generic parameter for the input stream type
438+
# yet, for simplicity.
439+
440+
431441
def test_item(func, description):
432442
@Parser
433443
def test_item_parser(stream, index):
@@ -461,6 +471,7 @@ def string_from(*strings: str, transform: Callable[[str], str] = noop) -> Parser
461471
return reduce(operator.or_, [string(s, transform) for s in sorted(strings, key=len, reverse=True)])
462472

463473

474+
# TODO drop bytes support here
464475
def char_from(string):
465476
if isinstance(string, bytes):
466477
return test_char(lambda c: c in string, b"[" + string + b"]")
@@ -509,6 +520,12 @@ def from_enum(enum_cls: type[E], transform: Callable = noop) -> Parser[E]:
509520
return reduce(operator.or_, [string(value, transform=transform).result(enum_item) for value, enum_item in items])
510521

511522

523+
# TODO how do we type a forward_declaration instance? For a typical usage, see
524+
# examples/json.py. I think this is probably a recursive type issue which is probably
525+
# mirroring the recursive definition issues that forward_declaration is designed to solve.
526+
# Cutting the recursive knot might be harder at the type level?
527+
528+
512529
class forward_declaration(Parser):
513530
"""
514531
An empty parser that can be used as a forward declaration,

0 commit comments

Comments
 (0)