|
19 | 19 |
|
20 | 20 | # Parser[str] is a subtype of Parser[Union[str, int]] |
21 | 21 | # 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. |
23 | 25 |
|
24 | 26 | OUT = TypeVar("OUT") |
25 | 27 | OUT1 = TypeVar("OUT1") |
@@ -428,6 +430,14 @@ def regex_parser(stream, index): |
428 | 430 | return regex_parser |
429 | 431 |
|
430 | 432 |
|
| 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 | + |
431 | 441 | def test_item(func, description): |
432 | 442 | @Parser |
433 | 443 | def test_item_parser(stream, index): |
@@ -461,6 +471,7 @@ def string_from(*strings: str, transform: Callable[[str], str] = noop) -> Parser |
461 | 471 | return reduce(operator.or_, [string(s, transform) for s in sorted(strings, key=len, reverse=True)]) |
462 | 472 |
|
463 | 473 |
|
| 474 | +# TODO drop bytes support here |
464 | 475 | def char_from(string): |
465 | 476 | if isinstance(string, bytes): |
466 | 477 | 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]: |
509 | 520 | return reduce(operator.or_, [string(value, transform=transform).result(enum_item) for value, enum_item in items]) |
510 | 521 |
|
511 | 522 |
|
| 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 | + |
512 | 529 | class forward_declaration(Parser): |
513 | 530 | """ |
514 | 531 | An empty parser that can be used as a forward declaration, |
|
0 commit comments