Mercurial > hg-stable
changeset 51738:0e16efe30866
typing: add a few trivial type hints to `mercurial/templater.py`
Since hg 3dbc7b1ecaba, pytype started inferring that the second value in the
tuple is `BinaryIO`, but still hasn't been able to figure out the rest of
`open_template()`. We can be more precise.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 10 Jul 2024 18:34:47 -0400 |
parents | df6ce326936f |
children | be6d8ea6d3d2 |
files | mercurial/templater.py |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Wed Jul 10 18:19:32 2024 -0400 +++ b/mercurial/templater.py Wed Jul 10 18:34:47 2024 -0400 @@ -69,6 +69,12 @@ import abc import os +from typing import ( + BinaryIO, + Optional, + Tuple, +) + from .i18n import _ from .pycompat import ( FileNotFoundError, @@ -1121,7 +1127,9 @@ return path if os.path.isdir(path) else None -def open_template(name, templatepath=None): +def open_template( + name: bytes, templatepath: Optional[bytes] = None +) -> Tuple[bytes, BinaryIO]: """returns a file-like object for the given template, and its full path If the name is a relative path and we're in a frozen binary, the template @@ -1156,7 +1164,9 @@ ) -def try_open_template(name, templatepath=None): +def try_open_template( + name: bytes, templatepath: Optional[bytes] = None +) -> Tuple[Optional[bytes], Optional[BinaryIO]]: try: return open_template(name, templatepath) except (EnvironmentError, ImportError):