Mercurial > hg-stable
view tests/test-config-parselist.py @ 51928:ad83e4f9b40e
typing: correct pytype mistakes in `mercurial/vfs.py`
With the previous changes in this series (prior to merging the *.pyi file), this
wasn't too bad- the only definitively wrong things were the `data` argument to
`writelines()`, and the return type on `backgroundclosing()` (both of these
errors were dropped in the previous commit; for some reason pytype doesn't like
`contextlib._GeneratorContextManager`, even though that's what it determined it
is):
File "/mnt/c/Users/Matt/hg/mercurial/vfs.py", line 411, in abstractvfs:
Bad return type 'contextlib._GeneratorContextManager' for generator function abstractvfs.backgroundclosing [bad-yield-annotation]
Expected Generator, Iterable or Iterator
PyCharm thinks this is `Generator[backgroundfilecloser], Any, None]`, which can
be reduced to `Iterator[backgroundfilecloser]`, but pytype flagged the line that
calls `yield` without an argument unless it's also `Optional`. PyCharm is happy
either way. For some reason, `Iterable` didn't work for pytype:
File "/mnt/c/Users/Matt/hg/mercurial/vfs.py", line 390, in abstractvfs:
Function contextlib.contextmanager was called with the wrong arguments [wrong-arg-types]
Expected: (func: Callable[[Any], Iterator])
Actually passed: (func: Callable[[Any, Any, Any], Iterable[Optional[Any]]])
Attributes of protocol Iterator[_T_co] are not implemented on Iterable[Optional[Any]]: __next__
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 20 Sep 2024 16:36:28 -0400 |
parents | 6961eca0b3ee |
children |
line wrap: on
line source
""" List-valued configuration keys have an ad-hoc microsyntax. From `hg help config`: > List values are separated by whitespace or comma, except when values are > placed in double quotation marks: > > allow_read = "John Doe, PhD", brian, betty > > Quotation marks can be escaped by prefixing them with a backslash. Only > quotation marks at the beginning of a word is counted as a quotation > (e.g., ``foo"bar baz`` is the list of ``foo"bar`` and ``baz``). That help documentation is fairly light on details, the actual parser has many other edge cases. This test tries to cover them. """ from mercurial.utils import stringutil def assert_parselist(input, expected): result = stringutil.parselist(input) if result != expected: raise AssertionError( "parse_input(%r)\n got %r\nexpected %r" % (input, result, expected) ) # Keep these Python tests in sync with the Rust ones in `rust/hg-core/src/config/values.rs` assert_parselist(b'', []) assert_parselist(b',', []) assert_parselist(b'A', [b'A']) assert_parselist(b'B,B', [b'B', b'B']) assert_parselist(b', C, ,C,', [b'C', b'C']) assert_parselist(b'"', [b'"']) assert_parselist(b'""', [b'', b'']) assert_parselist(b'D,"', [b'D', b'"']) assert_parselist(b'E,""', [b'E', b'', b'']) assert_parselist(b'"F,F"', [b'F,F']) assert_parselist(b'"G,G', [b'"G', b'G']) assert_parselist(b'"H \\",\\"H', [b'"H', b',', b'H']) assert_parselist(b'I,I"', [b'I', b'I"']) assert_parselist(b'J,"J', [b'J', b'"J']) assert_parselist(b'K K', [b'K', b'K']) assert_parselist(b'"K" K', [b'K', b'K']) assert_parselist(b'L\tL', [b'L', b'L']) assert_parselist(b'"L"\tL', [b'L', b'', b'L']) assert_parselist(b'M\x0bM', [b'M', b'M']) assert_parselist(b'"M"\x0bM', [b'M', b'', b'M']) assert_parselist(b'"N" , ,"', [b'N"']) assert_parselist(b'" ,O, ', [b'"', b'O'])