Patchwork [py3,resend] py3: initial type hinting stubs

login
register
mail settings
Submitter Martijn Pieters
Date March 15, 2017, 6:09 p.m.
Message ID <c363e933a66bb85ddbfe.1489601393@jlzhang-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/19368/
State Deferred
Headers show

Comments

Martijn Pieters - March 15, 2017, 6:09 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1489356745 25200
#      Sun Mar 12 15:12:25 2017 -0700
# Node ID c363e933a66bb85ddbfe8301bbfd246ecaad95d6
# Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
py3: initial type hinting stubs

These are stub files to be used by mypy and future tooling to check type hints
in Python 3. These files are complete for the current state of the covered
modules. Future tooling should ensure that these are kept in sync.
Martijn Pieters - March 15, 2017, 6:11 p.m.
I had to resend this as I had overdialled the DMARC settings on my domain.
Standards, Y U no support mailinglist forwarding properly.

On 15 March 2017 at 11:09, Martijn Pieters <mj@zopatista.com> wrote:

> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1489356745 25200
> #      Sun Mar 12 15:12:25 2017 -0700
> # Node ID c363e933a66bb85ddbfe8301bbfd246ecaad95d6
> # Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
> py3: initial type hinting stubs
>
> These are stub files to be used by mypy and future tooling to check type
> hints
> in Python 3. These files are complete for the current state of the covered
> modules. Future tooling should ensure that these are kept in sync.
>
> diff --git a/types/.flake8 b/types/.flake8
> new file mode 100644
> --- /dev/null
> +++ b/types/.flake8
> @@ -0,0 +1,13 @@
> +# Some PEP8 deviations are considered irrelevant to stub files:
> +# E704 multiple statements on one line (def)
> +# E301 expected 1 blank line
> +# E302 expected 2 blank lines
> +# E501 line too long
> +# F401 imported but unused
> +# E701 multiple statements on one line (colon)
> +# F811 redefinition
> +# E305 expected 2 blank lines
> +
> +[flake8]
> +ignore = F401, F811, E301, E302, E305, E501, E701, E704, B303
> +
> diff --git a/types/mercurial/__init__.pyi b/types/mercurial/__init__.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/__init__.pyi
> @@ -0,0 +1,22 @@
> +# Stubs for mercurial (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from tokenize import TokenInfo
> +from types import ModuleType
> +from typing import Any, Generator, Optional, Sequence, Union
> +import importlib.abc
> +import importlib.machinery
> +
> +modulepolicy = ...  # type: str
> +
> +# hgimporter is only used in Python 2
> +# class hgimporter: ...
> +
> +class hgpathentryfinder(importlib.abc.MetaPathFinder): ...
> +
> +def replacetokens(tokens: Sequence[TokenInfo], fullname: str) ->
> Generator[TokenInfo, None, None]: ...
> +
> +BYTECODEHEADER = ...  # type: bytes
> +
> +class hgloader(importlib.machinery.SourceFileLoader): ...
> diff --git a/types/mercurial/config.pyi b/types/mercurial/config.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/config.pyi
> @@ -0,0 +1,27 @@
> +# Stubs for mercurial.config (Python 3.6)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from typing import Any, BinaryIO, Callable, Container, Generator,
> ItemsView, List, Mapping, Optional, Sequence, Tuple, Union
> +from .i18n import _ as _
> +
> +# Config is backed up as a (section, item, value, source) tuple; a
> two-item tuple models a missing entry
> +_CfgBackup = Union[Tuple[bytes, bytes, Any, bytes], Tuple[bytes, bytes]]
> +
> +class config:
> +    def __init__(self, data: Optional[config] = ..., includepaths:
> Optional[Sequence[bytes]] = ...) -> None: ...
> +    def copy(self) -> config: ...
> +    def __contains__(self, section: bytes): ...
> +    def hasitem(self, section: bytes, item: bytes): ...
> +    def __getitem__(self, section: bytes): ...
> +    def __iter__(self) -> Generator[bytes, None, None]: ...
> +    def update(self, src: config) -> None: ...
> +    def get(self, section: bytes, item: bytes, default: Optional[Any] =
> ...) -> Optional[Any]: ...
> +    def backup(self, section: bytes, item: bytes) -> _CfgBackup: ...
> +    def source(self, section: bytes, item: bytes) -> bytes: ...
> +    def sections(self) -> List[bytes]: ...
> +    def items(self, section: bytes) -> ItemsView[bytes, Any]: ...
> +    def set(self, section: bytes, item: bytes, value: Any, source: bytes
> = ...) -> None: ...
> +    def restore(self, data: _CfgBackup) -> None: ...
> +    def parse(self, src: bytes, data: bytes, sections:
> Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] =
> ..., include: Optional[Callable[..., None]] = ...): ...
> +    def read(self, path: bytes, fp: Optional[BinaryIO] = ..., sections:
> Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] =
> ...) -> None: ...
> diff --git a/types/mercurial/policy.pyi b/types/mercurial/policy.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/policy.pyi
> @@ -0,0 +1,9 @@
> +# Stubs for mercurial.policy (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from typing import Any, Tuple
> +
> +policy = ...  # type: bytes
> +policynoc = ...  # type: Tuple[bytes, ...]
> +policynocffi = ...  # type: Tuple[bytes, ...]
> diff --git a/types/mercurial/ui.pyi b/types/mercurial/ui.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/ui.pyi
> @@ -0,0 +1,119 @@
> +# Stubs for mercurial.ui (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from types import TracebackType
> +from typing import Any, BinaryIO, Callable, Container, ContextManager,
> Generator, ItemsView, List, Mapping, MutableMapping, Optional, Sequence,
> SupportsInt, Tuple, Type, Union
> +from .config import _CfgBackup
> +from .formatter import baseformatter
> +from .i18n import _ as _
> +from .node import hex as hex
> +from .progress import progbar
> +from .url import url
> +
> +import urllib.request as urlreq
> +
> +_OneNameOrMultiple = Union[bytes, Sequence[bytes]]
> +
> +samplehgrcs = ...  # type: MutableMapping[bytes, bytes]
> +
> +class httppasswordmgrdbproxy:
> +    def __init__(self) -> None: ...
> +    def add_password(self, realm: str, uri: Union[str, Sequence[str]],
> user: str, passwd: str) -> None: ...
> +    def find_user_password(self, realm: str, authuri: str) ->
> Tuple[Optional[str], Optional[str]]: ...
> +
> +class ui:
> +    quiet = ...  # type: bool
> +    callhooks = ...  # type: bool
> +    insecureconnections = ...  # type: bool
> +    logblockedtimes = ...  # type: bool
> +    fout = ...  # type: BinaryIO
> +    ferr = ...  # type: BinaryIO
> +    fin = ...  # type: BinaryIO
> +    pageractive = ...  # type: bool
> +    environ = ...  # type: MutableMapping[bytes, bytes]
> +    httppasswordmgrdb = ...  # type: httppasswordmgrdbproxy
> +    def __init__(self, src: Optional[ui] = ...) -> None: ...
> +    @classmethod
> +    def load(cls) -> ui: ...
> +    def copy(self) -> ui: ...
> +    def resetstate(self) -> None: ...
> +    def timeblockedsection(self, key: bytes) -> ContextManager: ...
> +    def formatter(self, topic: bytes, opts: Mapping[bytes, Any]) ->
> baseformatter: ...
> +    def readconfig(self, filename: bytes, root: Optional[bytes] = ...,
> trust: bool = ..., sections: Optional[Container[bytes]] = ..., remap:
> Optional[Mapping[bytes, bytes]] = ...) -> None: ...
> +    debugflag = ...  # type: bool
> +    verbose = ...  # type: bool
> +    tracebackflag = ...  # type: bool
> +    def fixconfig(self, root: Optional[bytes] = ..., section:
> Optional[bytes] = ...) -> None: ...
> +    def backupconfig(self, section: bytes, item: bytes) ->
> Tuple[_CfgBackup, _CfgBackup, _CfgBackup]: ...
> +    def restoreconfig(self, data: Tuple[_CfgBackup, _CfgBackup,
> _CfgBackup]) -> None: ...
> +    def setconfig(self, section: bytes, name: bytes, value: bytes,
> source: bytes = ...) -> None: ...
> +    def configsource(self, section: bytes, name: bytes, untrusted: bool =
> ...) -> bytes: ...
> +    def config(self, section: bytes, name: Union[bytes, Sequence[bytes]],
> default: Optional[Any] = ..., untrusted: bool = ...) -> Optional[Any]: ...
> +    def configsuboptions(self, section: bytes, name: bytes, default:
> Optional[Any] = ..., untrusted: bool = ...) -> Tuple[Optional[bytes],
> Mapping[bytes, Any]]: ...
> +    def configpath(self, section: bytes, name: _OneNameOrMultiple,
> default: Optional[bytes] = ..., untrusted: bool = ...) -> Optional[bytes]:
> ...
> +    def configbool(self, section: bytes, name: _OneNameOrMultiple,
> default: bool = ..., untrusted: bool = ...) -> bool: ...
> +    def configwith(self, convert: Callable[[Any], Any], section: bytes,
> name: _OneNameOrMultiple, default: Optional[Any] = ..., desc: Optional[Any]
> = ..., untrusted: bool = ...): ...
> +    def configint(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[None, SupportsInt, str, bytes] = ..., untrusted: bool =
> ...)-> Optional[int]: ...
> +    def configbytes(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[bytes, int] = ..., untrusted: bool = ...) -> Optional[int]:
> ...
> +    def configlist(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[None, bytes, List[bytes]] = ..., untrusted: bool = ...) ->
> List[bytes]: ...
> +    def hasconfig(self, section: bytes, name: bytes, untrusted: bool =
> ...) -> bool: ...
> +    def has_section(self, section: bytes, untrusted: bool = ...) -> bool:
> ...
> +    def configitems(self, section: bytes, untrusted: bool = ...,
> ignoresub: bool = ...) -> ItemsView[bytes, Any]: ...
> +    def walkconfig(self, untrusted: bool = ...) -> Generator[Tuple[bytes,
> bytes, bytes], None, None]: ...
> +    def plain(self, feature: Optional[bytes] = ...) -> bool: ...
> +    def username(self) -> bytes: ...
> +    def shortuser(self, user: bytes) -> bytes: ...
> +    def expandpath(self, loc, default: Union[None, bytes, Tuple[bytes],
> List[bytes]] = ...) -> bytes: ...
> +    def paths(self) -> paths: ...
> +    def pushbuffer(self, error: bool = ..., subproc: bool = ..., labeled:
> bool = ...) -> None: ...
> +    def popbuffer(self) -> bytes: ...
> +    def write(self, *args: Any, **opts: Any) -> None: ...
> +    def write_err(self, *args: Any, **opts: Any) -> None: ...
> +    def flush(self) -> None: ...
> +    def disablepager(self) -> None: ...
> +    def pager(self, command: bytes) -> None: ...
> +    def interface(self, feature: bytes) -> bytes: ...
> +    def interactive(self) -> bool: ...
> +    def termwidth(self) -> int: ...
> +    def formatted(self) -> bool: ...
> +    def prompt(self, msg: bytes, default: bytes = ...) -> bytes: ...
> +    @staticmethod
> +    def extractchoices(prompt: bytes) -> Tuple[bytes, List[Tuple[bytes,
> bytes]]]: ...
> +    def promptchoice(self, prompt: bytes, default: int = ...) -> int: ...
> +    def getpass(self, prompt: Optional[bytes] = ..., default:
> Optional[bytes] = ...) -> Optional[bytes]: ...
> +    def status(self, *msg: Any, **opts: Any) -> None: ...
> +    def warn(self, *msg: Any, **opts: Any) -> None: ...
> +    def note(self, *msg: Any, **opts: Any) -> None: ...
> +    def debug(self, *msg: Any, **opts: Any) -> None: ...
> +    def edit(self, text: bytes, user: bytes, extra:
> Optional[Mapping[bytes, bytes]] = ..., editform: Optional[bytes] = ...,
> pending: Optional[bytes] = ..., repopath: Optional[bytes] = ...) -> bytes:
> ...
> +    def system(self, cmd: bytes, environ: Optional[Mapping[bytes, bytes]]
> = ..., cwd: Optional[bytes] = ..., onerr: Optional[Type[BaseException]] =
> ..., errprefix: Optional[bytes] = ...) -> int: ...
> +    def traceback(self, exc: Optional[Tuple[Type[BaseException],
> BaseException, TracebackType]] = ..., force: bool = ...) -> bool: ...
> +    def geteditor(self) -> bytes: ...
> +    def progress(self, topic: bytes, pos: float, item: bytes = ..., unit:
> bytes = ..., total: Optional[float] = ...) -> None: ...
> +    def log(self, service: bytes, *msg: Any, **opts: Any) -> None: ...
> +    def label(self, msg: bytes, label: bytes) -> bytes: ...
> +    def develwarn(self, msg: bytes, stacklevel: int = ..., config:
> Optional[bytes] = ...) -> None: ...
> +    def deprecwarn(self, msg: bytes, version: bytes) -> None: ...
> +    def exportableenviron(self) -> Mapping[bytes, bytes]: ...
> +    def configoverride(self, overrides: Mapping, source: bytes = ...) ->
> ContextManager: ...
> +
> +class paths(dict):
> +    def __init__(self, ui: ui) -> None: ...
> +    def getpath(self, name: bytes, default: Union[None, bytes,
> Tuple[bytes], List[bytes]] = ...) -> path: ...
> +
> +def pathsuboption(option: bytes, attr: str) -> Callable[[Callable],
> Callable]: ...
> +def pushurlpathoption(ui: ui, path: path, value: bytes) ->
> Optional[bytes]: ...
> +def pushrevpathoption(ui: ui, path: path, value: bytes) ->
> Optional[bytes]: ...
> +
> +class path:
> +    url = ...  # type: url
> +    branch = ...  # type: Optional[bytes]
> +    name = ...  # type: bytes
> +    rawloc = ...  # type: bytes
> +    loc = ...  # type: bytes
> +    def __init__(self, ui: ui, name: bytes, rawloc: Optional[bytes] =
> ..., suboptions: Optional[Mapping[bytes, bytes]] = ...) -> None: ...
> +    @property
> +    def suboptions(self) -> Mapping[bytes, bytes]: ...
> +
> +def getprogbar(ui: ui) -> progbar: ...
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Gregory Szorc - May 18, 2017, 6:22 p.m.
On Wed, Mar 15, 2017 at 11:09 AM, Martijn Pieters <mj@zopatista.com> wrote:

> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1489356745 25200
> #      Sun Mar 12 15:12:25 2017 -0700
> # Node ID c363e933a66bb85ddbfe8301bbfd246ecaad95d6
> # Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
> py3: initial type hinting stubs
>
> These are stub files to be used by mypy and future tooling to check type
> hints
> in Python 3. These files are complete for the current state of the covered
> modules. Future tooling should ensure that these are kept in sync.
>

Out of curiosity, does our recent decision to drop Python 2.6 make type
hinting easier in any way?


>
> diff --git a/types/.flake8 b/types/.flake8
> new file mode 100644
> --- /dev/null
> +++ b/types/.flake8
> @@ -0,0 +1,13 @@
> +# Some PEP8 deviations are considered irrelevant to stub files:
> +# E704 multiple statements on one line (def)
> +# E301 expected 1 blank line
> +# E302 expected 2 blank lines
> +# E501 line too long
> +# F401 imported but unused
> +# E701 multiple statements on one line (colon)
> +# F811 redefinition
> +# E305 expected 2 blank lines
> +
> +[flake8]
> +ignore = F401, F811, E301, E302, E305, E501, E701, E704, B303
> +
> diff --git a/types/mercurial/__init__.pyi b/types/mercurial/__init__.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/__init__.pyi
> @@ -0,0 +1,22 @@
> +# Stubs for mercurial (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from tokenize import TokenInfo
> +from types import ModuleType
> +from typing import Any, Generator, Optional, Sequence, Union
> +import importlib.abc
> +import importlib.machinery
> +
> +modulepolicy = ...  # type: str
> +
> +# hgimporter is only used in Python 2
> +# class hgimporter: ...
> +
> +class hgpathentryfinder(importlib.abc.MetaPathFinder): ...
> +
> +def replacetokens(tokens: Sequence[TokenInfo], fullname: str) ->
> Generator[TokenInfo, None, None]: ...
> +
> +BYTECODEHEADER = ...  # type: bytes
> +
> +class hgloader(importlib.machinery.SourceFileLoader): ...
> diff --git a/types/mercurial/config.pyi b/types/mercurial/config.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/config.pyi
> @@ -0,0 +1,27 @@
> +# Stubs for mercurial.config (Python 3.6)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from typing import Any, BinaryIO, Callable, Container, Generator,
> ItemsView, List, Mapping, Optional, Sequence, Tuple, Union
> +from .i18n import _ as _
> +
> +# Config is backed up as a (section, item, value, source) tuple; a
> two-item tuple models a missing entry
> +_CfgBackup = Union[Tuple[bytes, bytes, Any, bytes], Tuple[bytes, bytes]]
> +
> +class config:
> +    def __init__(self, data: Optional[config] = ..., includepaths:
> Optional[Sequence[bytes]] = ...) -> None: ...
> +    def copy(self) -> config: ...
> +    def __contains__(self, section: bytes): ...
> +    def hasitem(self, section: bytes, item: bytes): ...
> +    def __getitem__(self, section: bytes): ...
> +    def __iter__(self) -> Generator[bytes, None, None]: ...
> +    def update(self, src: config) -> None: ...
> +    def get(self, section: bytes, item: bytes, default: Optional[Any] =
> ...) -> Optional[Any]: ...
> +    def backup(self, section: bytes, item: bytes) -> _CfgBackup: ...
> +    def source(self, section: bytes, item: bytes) -> bytes: ...
> +    def sections(self) -> List[bytes]: ...
> +    def items(self, section: bytes) -> ItemsView[bytes, Any]: ...
> +    def set(self, section: bytes, item: bytes, value: Any, source: bytes
> = ...) -> None: ...
> +    def restore(self, data: _CfgBackup) -> None: ...
> +    def parse(self, src: bytes, data: bytes, sections:
> Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] =
> ..., include: Optional[Callable[..., None]] = ...): ...
> +    def read(self, path: bytes, fp: Optional[BinaryIO] = ..., sections:
> Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] =
> ...) -> None: ...
> diff --git a/types/mercurial/policy.pyi b/types/mercurial/policy.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/policy.pyi
> @@ -0,0 +1,9 @@
> +# Stubs for mercurial.policy (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from typing import Any, Tuple
> +
> +policy = ...  # type: bytes
> +policynoc = ...  # type: Tuple[bytes, ...]
> +policynocffi = ...  # type: Tuple[bytes, ...]
> diff --git a/types/mercurial/ui.pyi b/types/mercurial/ui.pyi
> new file mode 100644
> --- /dev/null
> +++ b/types/mercurial/ui.pyi
> @@ -0,0 +1,119 @@
> +# Stubs for mercurial.ui (Python 3.5)
> +#
> +# NOTE: This dynamically typed stub was automatically generated by
> stubgen.
> +
> +from types import TracebackType
> +from typing import Any, BinaryIO, Callable, Container, ContextManager,
> Generator, ItemsView, List, Mapping, MutableMapping, Optional, Sequence,
> SupportsInt, Tuple, Type, Union
> +from .config import _CfgBackup
> +from .formatter import baseformatter
> +from .i18n import _ as _
> +from .node import hex as hex
> +from .progress import progbar
> +from .url import url
> +
> +import urllib.request as urlreq
> +
> +_OneNameOrMultiple = Union[bytes, Sequence[bytes]]
> +
> +samplehgrcs = ...  # type: MutableMapping[bytes, bytes]
> +
> +class httppasswordmgrdbproxy:
> +    def __init__(self) -> None: ...
> +    def add_password(self, realm: str, uri: Union[str, Sequence[str]],
> user: str, passwd: str) -> None: ...
> +    def find_user_password(self, realm: str, authuri: str) ->
> Tuple[Optional[str], Optional[str]]: ...
> +
> +class ui:
> +    quiet = ...  # type: bool
> +    callhooks = ...  # type: bool
> +    insecureconnections = ...  # type: bool
> +    logblockedtimes = ...  # type: bool
> +    fout = ...  # type: BinaryIO
> +    ferr = ...  # type: BinaryIO
> +    fin = ...  # type: BinaryIO
> +    pageractive = ...  # type: bool
> +    environ = ...  # type: MutableMapping[bytes, bytes]
> +    httppasswordmgrdb = ...  # type: httppasswordmgrdbproxy
> +    def __init__(self, src: Optional[ui] = ...) -> None: ...
> +    @classmethod
> +    def load(cls) -> ui: ...
> +    def copy(self) -> ui: ...
> +    def resetstate(self) -> None: ...
> +    def timeblockedsection(self, key: bytes) -> ContextManager: ...
> +    def formatter(self, topic: bytes, opts: Mapping[bytes, Any]) ->
> baseformatter: ...
> +    def readconfig(self, filename: bytes, root: Optional[bytes] = ...,
> trust: bool = ..., sections: Optional[Container[bytes]] = ..., remap:
> Optional[Mapping[bytes, bytes]] = ...) -> None: ...
> +    debugflag = ...  # type: bool
> +    verbose = ...  # type: bool
> +    tracebackflag = ...  # type: bool
> +    def fixconfig(self, root: Optional[bytes] = ..., section:
> Optional[bytes] = ...) -> None: ...
> +    def backupconfig(self, section: bytes, item: bytes) ->
> Tuple[_CfgBackup, _CfgBackup, _CfgBackup]: ...
> +    def restoreconfig(self, data: Tuple[_CfgBackup, _CfgBackup,
> _CfgBackup]) -> None: ...
> +    def setconfig(self, section: bytes, name: bytes, value: bytes,
> source: bytes = ...) -> None: ...
> +    def configsource(self, section: bytes, name: bytes, untrusted: bool =
> ...) -> bytes: ...
> +    def config(self, section: bytes, name: Union[bytes, Sequence[bytes]],
> default: Optional[Any] = ..., untrusted: bool = ...) -> Optional[Any]: ...
> +    def configsuboptions(self, section: bytes, name: bytes, default:
> Optional[Any] = ..., untrusted: bool = ...) -> Tuple[Optional[bytes],
> Mapping[bytes, Any]]: ...
> +    def configpath(self, section: bytes, name: _OneNameOrMultiple,
> default: Optional[bytes] = ..., untrusted: bool = ...) -> Optional[bytes]:
> ...
> +    def configbool(self, section: bytes, name: _OneNameOrMultiple,
> default: bool = ..., untrusted: bool = ...) -> bool: ...
> +    def configwith(self, convert: Callable[[Any], Any], section: bytes,
> name: _OneNameOrMultiple, default: Optional[Any] = ..., desc: Optional[Any]
> = ..., untrusted: bool = ...): ...
> +    def configint(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[None, SupportsInt, str, bytes] = ..., untrusted: bool =
> ...)-> Optional[int]: ...
> +    def configbytes(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[bytes, int] = ..., untrusted: bool = ...) -> Optional[int]:
> ...
> +    def configlist(self, section: bytes, name: _OneNameOrMultiple,
> default: Union[None, bytes, List[bytes]] = ..., untrusted: bool = ...) ->
> List[bytes]: ...
> +    def hasconfig(self, section: bytes, name: bytes, untrusted: bool =
> ...) -> bool: ...
> +    def has_section(self, section: bytes, untrusted: bool = ...) -> bool:
> ...
> +    def configitems(self, section: bytes, untrusted: bool = ...,
> ignoresub: bool = ...) -> ItemsView[bytes, Any]: ...
> +    def walkconfig(self, untrusted: bool = ...) -> Generator[Tuple[bytes,
> bytes, bytes], None, None]: ...
> +    def plain(self, feature: Optional[bytes] = ...) -> bool: ...
> +    def username(self) -> bytes: ...
> +    def shortuser(self, user: bytes) -> bytes: ...
> +    def expandpath(self, loc, default: Union[None, bytes, Tuple[bytes],
> List[bytes]] = ...) -> bytes: ...
> +    def paths(self) -> paths: ...
> +    def pushbuffer(self, error: bool = ..., subproc: bool = ..., labeled:
> bool = ...) -> None: ...
> +    def popbuffer(self) -> bytes: ...
> +    def write(self, *args: Any, **opts: Any) -> None: ...
> +    def write_err(self, *args: Any, **opts: Any) -> None: ...
> +    def flush(self) -> None: ...
> +    def disablepager(self) -> None: ...
> +    def pager(self, command: bytes) -> None: ...
> +    def interface(self, feature: bytes) -> bytes: ...
> +    def interactive(self) -> bool: ...
> +    def termwidth(self) -> int: ...
> +    def formatted(self) -> bool: ...
> +    def prompt(self, msg: bytes, default: bytes = ...) -> bytes: ...
> +    @staticmethod
> +    def extractchoices(prompt: bytes) -> Tuple[bytes, List[Tuple[bytes,
> bytes]]]: ...
> +    def promptchoice(self, prompt: bytes, default: int = ...) -> int: ...
> +    def getpass(self, prompt: Optional[bytes] = ..., default:
> Optional[bytes] = ...) -> Optional[bytes]: ...
> +    def status(self, *msg: Any, **opts: Any) -> None: ...
> +    def warn(self, *msg: Any, **opts: Any) -> None: ...
> +    def note(self, *msg: Any, **opts: Any) -> None: ...
> +    def debug(self, *msg: Any, **opts: Any) -> None: ...
> +    def edit(self, text: bytes, user: bytes, extra:
> Optional[Mapping[bytes, bytes]] = ..., editform: Optional[bytes] = ...,
> pending: Optional[bytes] = ..., repopath: Optional[bytes] = ...) -> bytes:
> ...
> +    def system(self, cmd: bytes, environ: Optional[Mapping[bytes, bytes]]
> = ..., cwd: Optional[bytes] = ..., onerr: Optional[Type[BaseException]] =
> ..., errprefix: Optional[bytes] = ...) -> int: ...
> +    def traceback(self, exc: Optional[Tuple[Type[BaseException],
> BaseException, TracebackType]] = ..., force: bool = ...) -> bool: ...
> +    def geteditor(self) -> bytes: ...
> +    def progress(self, topic: bytes, pos: float, item: bytes = ..., unit:
> bytes = ..., total: Optional[float] = ...) -> None: ...
> +    def log(self, service: bytes, *msg: Any, **opts: Any) -> None: ...
> +    def label(self, msg: bytes, label: bytes) -> bytes: ...
> +    def develwarn(self, msg: bytes, stacklevel: int = ..., config:
> Optional[bytes] = ...) -> None: ...
> +    def deprecwarn(self, msg: bytes, version: bytes) -> None: ...
> +    def exportableenviron(self) -> Mapping[bytes, bytes]: ...
> +    def configoverride(self, overrides: Mapping, source: bytes = ...) ->
> ContextManager: ...
> +
> +class paths(dict):
> +    def __init__(self, ui: ui) -> None: ...
> +    def getpath(self, name: bytes, default: Union[None, bytes,
> Tuple[bytes], List[bytes]] = ...) -> path: ...
> +
> +def pathsuboption(option: bytes, attr: str) -> Callable[[Callable],
> Callable]: ...
> +def pushurlpathoption(ui: ui, path: path, value: bytes) ->
> Optional[bytes]: ...
> +def pushrevpathoption(ui: ui, path: path, value: bytes) ->
> Optional[bytes]: ...
> +
> +class path:
> +    url = ...  # type: url
> +    branch = ...  # type: Optional[bytes]
> +    name = ...  # type: bytes
> +    rawloc = ...  # type: bytes
> +    loc = ...  # type: bytes
> +    def __init__(self, ui: ui, name: bytes, rawloc: Optional[bytes] =
> ..., suboptions: Optional[Mapping[bytes, bytes]] = ...) -> None: ...
> +    @property
> +    def suboptions(self) -> Mapping[bytes, bytes]: ...
> +
> +def getprogbar(ui: ui) -> progbar: ...
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Martijn Pieters - May 18, 2017, 6:52 p.m.
On 18 May 2017, at 19:22, Gregory Szorc <gregory.szorc@gmail.com> wrote:
> On Wed, Mar 15, 2017 at 11:09 AM, Martijn Pieters <mj@zopatista.com <mailto:mj@zopatista.com>> wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com <mailto:mjpieters@fb.com>>
> # Date 1489356745 25200
> #      Sun Mar 12 15:12:25 2017 -0700
> # Node ID c363e933a66bb85ddbfe8301bbfd246ecaad95d6
> # Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
> py3: initial type hinting stubs
> 
> These are stub files to be used by mypy and future tooling to check type hints
> in Python 3. These files are complete for the current state of the covered
> modules. Future tooling should ensure that these are kept in sync.
> 
> Out of curiosity, does our recent decision to drop Python 2.6 make type hinting easier in any way?

Python 2.x is not being type hinted.

You could say that simplifying the backwards-compatibility shims to remove Py 2.6 compatibility may make a small difference, but the syntax changes are not all that big between 2.6 and 2.7 (set literals, dict and set comprehensions, multiple context managers per `with` statement, that's it really).

So no, I don't think it makes a difference.

Martijn
Gregory Szorc - May 18, 2017, 9:59 p.m.
On Thu, May 18, 2017 at 11:52 AM, Martijn Pieters <mj@zopatista.com> wrote:

> On 18 May 2017, at 19:22, Gregory Szorc <gregory.szorc@gmail.com> wrote:
>
> On Wed, Mar 15, 2017 at 11:09 AM, Martijn Pieters <mj@zopatista.com> wro
> te:
>
>> # HG changeset patch
>> # User Martijn Pieters <mjpieters@fb.com>
>> # Date 1489356745 25200
>> #      Sun Mar 12 15:12:25 2017 -0700
>> # Node ID c363e933a66bb85ddbfe8301bbfd246ecaad95d6
>> # Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
>> py3: initial type hinting stubs
>>
>> These are stub files to be used by mypy and future tooling to check type
>> hints
>> in Python 3. These files are complete for the current state of the covered
>> modules. Future tooling should ensure that these are kept in sync.
>>
>
> Out of curiosity, does our recent decision to drop Python 2.6 make type
> hinting easier in any way?
>
>
> Python 2.x is not being type hinted.
>
> You could say that simplifying the backwards-compatibility shims to remove
> Py 2.6 compatibility may make a small difference, but the syntax changes
> are not all that big between 2.6 and 2.7 (set literals, dict and set
> comprehensions, multiple context managers per `with` statement, that's it
> really).
>
> So no, I don't think it makes a difference.
>

Boo :(

FWIW, Augie and I were IRC chatting about
https://github.com/nvbn/py-backwards a few weeks back. Seems like a pretty
decent source transformer for backporting some Python 3 behavior and syntax
to Python 2.7. In the case of type annotations, it will allow us to use
function annotations while still supporting 2.7. But I don't think we can
realistically switch to that model until Mercurial is fully supported on
Python 3 and most developers are thinking Python 3 first. Then again, type
annotations are a big deal. So I could be convinced to perform source
transformation for 2.7 *now* if it didn't hurt run-time performance or
incur substantial developer overhead.

Patch

diff --git a/types/.flake8 b/types/.flake8
new file mode 100644
--- /dev/null
+++ b/types/.flake8
@@ -0,0 +1,13 @@ 
+# Some PEP8 deviations are considered irrelevant to stub files:
+# E704 multiple statements on one line (def)
+# E301 expected 1 blank line
+# E302 expected 2 blank lines
+# E501 line too long
+# F401 imported but unused
+# E701 multiple statements on one line (colon)
+# F811 redefinition
+# E305 expected 2 blank lines
+
+[flake8]
+ignore = F401, F811, E301, E302, E305, E501, E701, E704, B303
+
diff --git a/types/mercurial/__init__.pyi b/types/mercurial/__init__.pyi
new file mode 100644
--- /dev/null
+++ b/types/mercurial/__init__.pyi
@@ -0,0 +1,22 @@ 
+# Stubs for mercurial (Python 3.5)
+#
+# NOTE: This dynamically typed stub was automatically generated by stubgen.
+
+from tokenize import TokenInfo
+from types import ModuleType
+from typing import Any, Generator, Optional, Sequence, Union
+import importlib.abc
+import importlib.machinery
+
+modulepolicy = ...  # type: str
+
+# hgimporter is only used in Python 2
+# class hgimporter: ...
+
+class hgpathentryfinder(importlib.abc.MetaPathFinder): ...
+
+def replacetokens(tokens: Sequence[TokenInfo], fullname: str) -> Generator[TokenInfo, None, None]: ...
+
+BYTECODEHEADER = ...  # type: bytes
+
+class hgloader(importlib.machinery.SourceFileLoader): ...
diff --git a/types/mercurial/config.pyi b/types/mercurial/config.pyi
new file mode 100644
--- /dev/null
+++ b/types/mercurial/config.pyi
@@ -0,0 +1,27 @@ 
+# Stubs for mercurial.config (Python 3.6)
+#
+# NOTE: This dynamically typed stub was automatically generated by stubgen.
+
+from typing import Any, BinaryIO, Callable, Container, Generator, ItemsView, List, Mapping, Optional, Sequence, Tuple, Union
+from .i18n import _ as _
+
+# Config is backed up as a (section, item, value, source) tuple; a two-item tuple models a missing entry
+_CfgBackup = Union[Tuple[bytes, bytes, Any, bytes], Tuple[bytes, bytes]]
+
+class config:
+    def __init__(self, data: Optional[config] = ..., includepaths: Optional[Sequence[bytes]] = ...) -> None: ...
+    def copy(self) -> config: ...
+    def __contains__(self, section: bytes): ...
+    def hasitem(self, section: bytes, item: bytes): ...
+    def __getitem__(self, section: bytes): ...
+    def __iter__(self) -> Generator[bytes, None, None]: ...
+    def update(self, src: config) -> None: ...
+    def get(self, section: bytes, item: bytes, default: Optional[Any] = ...) -> Optional[Any]: ...
+    def backup(self, section: bytes, item: bytes) -> _CfgBackup: ...
+    def source(self, section: bytes, item: bytes) -> bytes: ...
+    def sections(self) -> List[bytes]: ...
+    def items(self, section: bytes) -> ItemsView[bytes, Any]: ...
+    def set(self, section: bytes, item: bytes, value: Any, source: bytes = ...) -> None: ...
+    def restore(self, data: _CfgBackup) -> None: ...
+    def parse(self, src: bytes, data: bytes, sections: Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] = ..., include: Optional[Callable[..., None]] = ...): ...
+    def read(self, path: bytes, fp: Optional[BinaryIO] = ..., sections: Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] = ...) -> None: ...
diff --git a/types/mercurial/policy.pyi b/types/mercurial/policy.pyi
new file mode 100644
--- /dev/null
+++ b/types/mercurial/policy.pyi
@@ -0,0 +1,9 @@ 
+# Stubs for mercurial.policy (Python 3.5)
+#
+# NOTE: This dynamically typed stub was automatically generated by stubgen.
+
+from typing import Any, Tuple
+
+policy = ...  # type: bytes
+policynoc = ...  # type: Tuple[bytes, ...]
+policynocffi = ...  # type: Tuple[bytes, ...]
diff --git a/types/mercurial/ui.pyi b/types/mercurial/ui.pyi
new file mode 100644
--- /dev/null
+++ b/types/mercurial/ui.pyi
@@ -0,0 +1,119 @@ 
+# Stubs for mercurial.ui (Python 3.5)
+#
+# NOTE: This dynamically typed stub was automatically generated by stubgen.
+
+from types import TracebackType
+from typing import Any, BinaryIO, Callable, Container, ContextManager, Generator, ItemsView, List, Mapping, MutableMapping, Optional, Sequence, SupportsInt, Tuple, Type, Union
+from .config import _CfgBackup
+from .formatter import baseformatter
+from .i18n import _ as _
+from .node import hex as hex
+from .progress import progbar
+from .url import url
+
+import urllib.request as urlreq
+
+_OneNameOrMultiple = Union[bytes, Sequence[bytes]]
+
+samplehgrcs = ...  # type: MutableMapping[bytes, bytes]
+
+class httppasswordmgrdbproxy:
+    def __init__(self) -> None: ...
+    def add_password(self, realm: str, uri: Union[str, Sequence[str]], user: str, passwd: str) -> None: ...
+    def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ...
+
+class ui:
+    quiet = ...  # type: bool
+    callhooks = ...  # type: bool
+    insecureconnections = ...  # type: bool
+    logblockedtimes = ...  # type: bool
+    fout = ...  # type: BinaryIO
+    ferr = ...  # type: BinaryIO
+    fin = ...  # type: BinaryIO
+    pageractive = ...  # type: bool
+    environ = ...  # type: MutableMapping[bytes, bytes]
+    httppasswordmgrdb = ...  # type: httppasswordmgrdbproxy
+    def __init__(self, src: Optional[ui] = ...) -> None: ...
+    @classmethod
+    def load(cls) -> ui: ...
+    def copy(self) -> ui: ...
+    def resetstate(self) -> None: ...
+    def timeblockedsection(self, key: bytes) -> ContextManager: ...
+    def formatter(self, topic: bytes, opts: Mapping[bytes, Any]) -> baseformatter: ...
+    def readconfig(self, filename: bytes, root: Optional[bytes] = ..., trust: bool = ..., sections: Optional[Container[bytes]] = ..., remap: Optional[Mapping[bytes, bytes]] = ...) -> None: ...
+    debugflag = ...  # type: bool
+    verbose = ...  # type: bool
+    tracebackflag = ...  # type: bool
+    def fixconfig(self, root: Optional[bytes] = ..., section: Optional[bytes] = ...) -> None: ...
+    def backupconfig(self, section: bytes, item: bytes) -> Tuple[_CfgBackup, _CfgBackup, _CfgBackup]: ...
+    def restoreconfig(self, data: Tuple[_CfgBackup, _CfgBackup, _CfgBackup]) -> None: ...
+    def setconfig(self, section: bytes, name: bytes, value: bytes, source: bytes = ...) -> None: ...
+    def configsource(self, section: bytes, name: bytes, untrusted: bool = ...) -> bytes: ...
+    def config(self, section: bytes, name: Union[bytes, Sequence[bytes]], default: Optional[Any] = ..., untrusted: bool = ...) -> Optional[Any]: ...
+    def configsuboptions(self, section: bytes, name: bytes, default: Optional[Any] = ..., untrusted: bool = ...) -> Tuple[Optional[bytes], Mapping[bytes, Any]]: ...
+    def configpath(self, section: bytes, name: _OneNameOrMultiple, default: Optional[bytes] = ..., untrusted: bool = ...) -> Optional[bytes]: ...
+    def configbool(self, section: bytes, name: _OneNameOrMultiple, default: bool = ..., untrusted: bool = ...) -> bool: ...
+    def configwith(self, convert: Callable[[Any], Any], section: bytes, name: _OneNameOrMultiple, default: Optional[Any] = ..., desc: Optional[Any] = ..., untrusted: bool = ...): ...
+    def configint(self, section: bytes, name: _OneNameOrMultiple, default: Union[None, SupportsInt, str, bytes] = ..., untrusted: bool = ...)-> Optional[int]: ...
+    def configbytes(self, section: bytes, name: _OneNameOrMultiple, default: Union[bytes, int] = ..., untrusted: bool = ...) -> Optional[int]: ...
+    def configlist(self, section: bytes, name: _OneNameOrMultiple, default: Union[None, bytes, List[bytes]] = ..., untrusted: bool = ...) -> List[bytes]: ...
+    def hasconfig(self, section: bytes, name: bytes, untrusted: bool = ...) -> bool: ...
+    def has_section(self, section: bytes, untrusted: bool = ...) -> bool: ...
+    def configitems(self, section: bytes, untrusted: bool = ..., ignoresub: bool = ...) -> ItemsView[bytes, Any]: ...
+    def walkconfig(self, untrusted: bool = ...) -> Generator[Tuple[bytes, bytes, bytes], None, None]: ...
+    def plain(self, feature: Optional[bytes] = ...) -> bool: ...
+    def username(self) -> bytes: ...
+    def shortuser(self, user: bytes) -> bytes: ...
+    def expandpath(self, loc, default: Union[None, bytes, Tuple[bytes], List[bytes]] = ...) -> bytes: ...
+    def paths(self) -> paths: ...
+    def pushbuffer(self, error: bool = ..., subproc: bool = ..., labeled: bool = ...) -> None: ...
+    def popbuffer(self) -> bytes: ...
+    def write(self, *args: Any, **opts: Any) -> None: ...
+    def write_err(self, *args: Any, **opts: Any) -> None: ...
+    def flush(self) -> None: ...
+    def disablepager(self) -> None: ...
+    def pager(self, command: bytes) -> None: ...
+    def interface(self, feature: bytes) -> bytes: ...
+    def interactive(self) -> bool: ...
+    def termwidth(self) -> int: ...
+    def formatted(self) -> bool: ...
+    def prompt(self, msg: bytes, default: bytes = ...) -> bytes: ...
+    @staticmethod
+    def extractchoices(prompt: bytes) -> Tuple[bytes, List[Tuple[bytes, bytes]]]: ...
+    def promptchoice(self, prompt: bytes, default: int = ...) -> int: ...
+    def getpass(self, prompt: Optional[bytes] = ..., default: Optional[bytes] = ...) -> Optional[bytes]: ...
+    def status(self, *msg: Any, **opts: Any) -> None: ...
+    def warn(self, *msg: Any, **opts: Any) -> None: ...
+    def note(self, *msg: Any, **opts: Any) -> None: ...
+    def debug(self, *msg: Any, **opts: Any) -> None: ...
+    def edit(self, text: bytes, user: bytes, extra: Optional[Mapping[bytes, bytes]] = ..., editform: Optional[bytes] = ..., pending: Optional[bytes] = ..., repopath: Optional[bytes] = ...) -> bytes: ...
+    def system(self, cmd: bytes, environ: Optional[Mapping[bytes, bytes]] = ..., cwd: Optional[bytes] = ..., onerr: Optional[Type[BaseException]] = ..., errprefix: Optional[bytes] = ...) -> int: ...
+    def traceback(self, exc: Optional[Tuple[Type[BaseException], BaseException, TracebackType]] = ..., force: bool = ...) -> bool: ...
+    def geteditor(self) -> bytes: ...
+    def progress(self, topic: bytes, pos: float, item: bytes = ..., unit: bytes = ..., total: Optional[float] = ...) -> None: ...
+    def log(self, service: bytes, *msg: Any, **opts: Any) -> None: ...
+    def label(self, msg: bytes, label: bytes) -> bytes: ...
+    def develwarn(self, msg: bytes, stacklevel: int = ..., config: Optional[bytes] = ...) -> None: ...
+    def deprecwarn(self, msg: bytes, version: bytes) -> None: ...
+    def exportableenviron(self) -> Mapping[bytes, bytes]: ...
+    def configoverride(self, overrides: Mapping, source: bytes = ...) -> ContextManager: ...
+
+class paths(dict):
+    def __init__(self, ui: ui) -> None: ...
+    def getpath(self, name: bytes, default: Union[None, bytes, Tuple[bytes], List[bytes]] = ...) -> path: ...
+
+def pathsuboption(option: bytes, attr: str) -> Callable[[Callable], Callable]: ...
+def pushurlpathoption(ui: ui, path: path, value: bytes) -> Optional[bytes]: ...
+def pushrevpathoption(ui: ui, path: path, value: bytes) -> Optional[bytes]: ...
+
+class path:
+    url = ...  # type: url
+    branch = ...  # type: Optional[bytes]
+    name = ...  # type: bytes
+    rawloc = ...  # type: bytes
+    loc = ...  # type: bytes
+    def __init__(self, ui: ui, name: bytes, rawloc: Optional[bytes] = ..., suboptions: Optional[Mapping[bytes, bytes]] = ...) -> None: ...
+    @property
+    def suboptions(self) -> Mapping[bytes, bytes]: ...
+
+def getprogbar(ui: ui) -> progbar: ...