-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typing of Parser's unbound methods
All credit due to "Finite State Machine" on the typing gitter, they're the one who had the idea of trying to type `self` in case that would make mypy happy. Which it absolutely does. This does make that use pattern easier to recommend, as it's fully typed as well.
- Loading branch information
Showing
2 changed files
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
from ua_parser import Parser, ParseResult, PartialParseResult | ||
from ua_parser import Domain, Parser, ParseResult, PartialParseResult | ||
|
||
|
||
def resolver(s: str, d: Domain) -> PartialParseResult: | ||
return PartialParseResult(d, None, None, None, s) | ||
|
||
|
||
def test_parser_utility() -> None: | ||
"""Tests that ``Parser``'s methods to behave as procedural | ||
helpers, for users who may not wish to instantiate a parser or | ||
something. | ||
Sadly the typing doesn't really play nicely with that. | ||
""" | ||
r = Parser.parse(lambda s, d: PartialParseResult(d, None, None, None, s), "a") # type: ignore | ||
|
||
r = Parser.parse(resolver, "a") | ||
assert r == ParseResult(None, None, None, "a") | ||
|
||
os = Parser.parse_os(resolver, "a") | ||
assert os is None |