Mercurial > public > mercurial-scm > hg
diff hgext/convert/common.py @ 51682:39033e7a6e0a
convert: stringify `shlex` class argument
The documentation is handwavy, but typeshed says this should be `str`[1]. I'm
not sure if this is the correct encoding (vs `fsencode` or "latin1" like the
tokens returned by the proxy class).
While we're here, we can add a few more type hints that would have caused pytype
to flag the problem.
[1] https://github.com/python/typeshed/blob/6a9b53e719a139c2d6b41cf265ed0990cf438192/stdlib/shlex.pyi#L51
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 11 Jul 2024 21:16:45 -0400 |
parents | 0eb515c7bec8 |
children | 1eab9e40c0c8 |
line wrap: on
line diff
--- a/hgext/convert/common.py Thu Jul 11 20:54:06 2024 -0400 +++ b/hgext/convert/common.py Thu Jul 11 21:16:45 2024 -0400 @@ -72,8 +72,10 @@ return _encodeornone(self._l.get_token()) @property - def infile(self): - return self._l.infile or b'<unknown>' + def infile(self) -> bytes: + if self._l.infile is not None: + return encoding.strtolocal(self._l.infile) + return b'<unknown>' @property def lineno(self) -> int: @@ -82,7 +84,7 @@ def shlexer( data=None, - filepath: Optional[str] = None, + filepath: Optional[bytes] = None, wordchars: Optional[bytes] = None, whitespace: Optional[bytes] = None, ): @@ -94,7 +96,8 @@ b'shlexer only accepts data or filepath, not both' ) data = data.decode('latin1') - l = shlex.shlex(data, infile=filepath, posix=True) + infile = encoding.strfromlocal(filepath) if filepath is not None else None + l = shlex.shlex(data, infile=infile, posix=True) if whitespace is not None: l.whitespace_split = True l.whitespace += whitespace.decode('latin1')