Skip to content

Commit c869d32

Browse files
authored
Merge pull request #232 from bluetech/pyi
2 parents d6aad84 + 59fd0d5 commit c869d32

13 files changed

+561
-3
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 120
3+
per-file-ignores =
4+
**/*.pyi:E252,E301,E302,E305,E501,E701,E704,F401,F811,F821

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.cache/
33
.tox/
44
__pycache__/
5+
.mypy_cache/
56

67
*.pyc
78
*.pyo

CHANGELOG

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
1.9.0 (TBD)
2+
===========
3+
4+
- Add type annotation stubs for the following modules:
5+
* ``py.error``
6+
* ``py.iniconfig``
7+
* ``py.path`` (not including SVN paths)
8+
* ``py.io``
9+
* ``py.xml``
10+
There are no plans to type other modules at this time.
11+
12+
The type annotations are provided in external .pyi files, not inline in the
13+
code, and may therefore contain small errors or omissions. If you use ``py``
14+
in conjunction with a type checker, and encounter any type errors you believe
15+
should be accepted, please report it in an issue.
16+
117
1.8.2 (2020-06-15)
218
==================
319

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include setup.py
55
include LICENSE
66
include conftest.py
77
include tox.ini
8+
recursive-include py *.pyi
89
graft doc
910
graft testing
1011
global-exclude *.pyc

py/__init__.pyi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Any
2+
3+
# py allows to use e.g. py.path.local even without importing py.path.
4+
# So import implicitly.
5+
from . import error
6+
from . import iniconfig
7+
from . import path
8+
from . import io
9+
from . import xml
10+
11+
__version__: str
12+
13+
# Untyped modules below here.
14+
std: Any
15+
test: Any
16+
process: Any
17+
apipkg: Any
18+
code: Any
19+
builtin: Any
20+
log: Any

py/_io/capture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TextIO(StringIO):
1313
def write(self, data):
1414
if not isinstance(data, unicode):
1515
data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
16-
StringIO.write(self, data)
16+
return StringIO.write(self, data)
1717
else:
1818
TextIO = StringIO
1919

@@ -24,7 +24,7 @@ class BytesIO(StringIO):
2424
def write(self, data):
2525
if isinstance(data, unicode):
2626
raise TypeError("not a byte value: %r" %(data,))
27-
StringIO.write(self, data)
27+
return StringIO.write(self, data)
2828

2929
patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'}
3030

@@ -266,7 +266,7 @@ def readouterr(self):
266266
err = self._readsnapshot(self.err.tmpfile)
267267
else:
268268
err = ""
269-
return [out, err]
269+
return out, err
270270

271271
def _readsnapshot(self, f):
272272
f.seek(0)

py/error.pyi

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
from typing import Any, Callable, TypeVar
2+
3+
_T = TypeVar('_T')
4+
5+
def checked_call(func: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...
6+
class Error(EnvironmentError): ...
7+
class EPERM(Error): ...
8+
class ENOENT(Error): ...
9+
class ESRCH(Error): ...
10+
class EINTR(Error): ...
11+
class EIO(Error): ...
12+
class ENXIO(Error): ...
13+
class E2BIG(Error): ...
14+
class ENOEXEC(Error): ...
15+
class EBADF(Error): ...
16+
class ECHILD(Error): ...
17+
class EAGAIN(Error): ...
18+
class ENOMEM(Error): ...
19+
class EACCES(Error): ...
20+
class EFAULT(Error): ...
21+
class ENOTBLK(Error): ...
22+
class EBUSY(Error): ...
23+
class EEXIST(Error): ...
24+
class EXDEV(Error): ...
25+
class ENODEV(Error): ...
26+
class ENOTDIR(Error): ...
27+
class EISDIR(Error): ...
28+
class EINVAL(Error): ...
29+
class ENFILE(Error): ...
30+
class EMFILE(Error): ...
31+
class ENOTTY(Error): ...
32+
class ETXTBSY(Error): ...
33+
class EFBIG(Error): ...
34+
class ENOSPC(Error): ...
35+
class ESPIPE(Error): ...
36+
class EROFS(Error): ...
37+
class EMLINK(Error): ...
38+
class EPIPE(Error): ...
39+
class EDOM(Error): ...
40+
class ERANGE(Error): ...
41+
class EDEADLCK(Error): ...
42+
class ENAMETOOLONG(Error): ...
43+
class ENOLCK(Error): ...
44+
class ENOSYS(Error): ...
45+
class ENOTEMPTY(Error): ...
46+
class ELOOP(Error): ...
47+
class EWOULDBLOCK(Error): ...
48+
class ENOMSG(Error): ...
49+
class EIDRM(Error): ...
50+
class ECHRNG(Error): ...
51+
class EL2NSYNC(Error): ...
52+
class EL3HLT(Error): ...
53+
class EL3RST(Error): ...
54+
class ELNRNG(Error): ...
55+
class EUNATCH(Error): ...
56+
class ENOCSI(Error): ...
57+
class EL2HLT(Error): ...
58+
class EBADE(Error): ...
59+
class EBADR(Error): ...
60+
class EXFULL(Error): ...
61+
class ENOANO(Error): ...
62+
class EBADRQC(Error): ...
63+
class EBADSLT(Error): ...
64+
class EDEADLOCK(Error): ...
65+
class EBFONT(Error): ...
66+
class ENOSTR(Error): ...
67+
class ENODATA(Error): ...
68+
class ETIME(Error): ...
69+
class ENOSR(Error): ...
70+
class ENONET(Error): ...
71+
class ENOPKG(Error): ...
72+
class EREMOTE(Error): ...
73+
class ENOLINK(Error): ...
74+
class EADV(Error): ...
75+
class ESRMNT(Error): ...
76+
class ECOMM(Error): ...
77+
class EPROTO(Error): ...
78+
class EMULTIHOP(Error): ...
79+
class EDOTDOT(Error): ...
80+
class EBADMSG(Error): ...
81+
class EOVERFLOW(Error): ...
82+
class ENOTUNIQ(Error): ...
83+
class EBADFD(Error): ...
84+
class EREMCHG(Error): ...
85+
class ELIBACC(Error): ...
86+
class ELIBBAD(Error): ...
87+
class ELIBSCN(Error): ...
88+
class ELIBMAX(Error): ...
89+
class ELIBEXEC(Error): ...
90+
class EILSEQ(Error): ...
91+
class ERESTART(Error): ...
92+
class ESTRPIPE(Error): ...
93+
class EUSERS(Error): ...
94+
class ENOTSOCK(Error): ...
95+
class EDESTADDRREQ(Error): ...
96+
class EMSGSIZE(Error): ...
97+
class EPROTOTYPE(Error): ...
98+
class ENOPROTOOPT(Error): ...
99+
class EPROTONOSUPPORT(Error): ...
100+
class ESOCKTNOSUPPORT(Error): ...
101+
class ENOTSUP(Error): ...
102+
class EOPNOTSUPP(Error): ...
103+
class EPFNOSUPPORT(Error): ...
104+
class EAFNOSUPPORT(Error): ...
105+
class EADDRINUSE(Error): ...
106+
class EADDRNOTAVAIL(Error): ...
107+
class ENETDOWN(Error): ...
108+
class ENETUNREACH(Error): ...
109+
class ENETRESET(Error): ...
110+
class ECONNABORTED(Error): ...
111+
class ECONNRESET(Error): ...
112+
class ENOBUFS(Error): ...
113+
class EISCONN(Error): ...
114+
class ENOTCONN(Error): ...
115+
class ESHUTDOWN(Error): ...
116+
class ETOOMANYREFS(Error): ...
117+
class ETIMEDOUT(Error): ...
118+
class ECONNREFUSED(Error): ...
119+
class EHOSTDOWN(Error): ...
120+
class EHOSTUNREACH(Error): ...
121+
class EALREADY(Error): ...
122+
class EINPROGRESS(Error): ...
123+
class ESTALE(Error): ...
124+
class EUCLEAN(Error): ...
125+
class ENOTNAM(Error): ...
126+
class ENAVAIL(Error): ...
127+
class EISNAM(Error): ...
128+
class EREMOTEIO(Error): ...
129+
class EDQUOT(Error): ...

py/iniconfig.pyi

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Callable, Iterator, Mapping, Optional, Tuple, TypeVar, Union
2+
from typing_extensions import Final
3+
4+
_D = TypeVar('_D')
5+
_T = TypeVar('_T')
6+
7+
class ParseError(Exception):
8+
path: Final[str]
9+
lineno: Final[int]
10+
msg: Final[str]
11+
def __init__(self, path: str, lineno: int, msg: str) -> None: ...
12+
13+
class _SectionWrapper:
14+
config: Final[IniConfig]
15+
name: Final[str]
16+
def __init__(self, config: IniConfig, name: str) -> None: ...
17+
def __getitem__(self, key: str) -> Optional[str]: ...
18+
def __iter__(self) -> Iterator[str]: ...
19+
def get(self, key: str, default: _D = ..., convert: Callable[[Optional[str]], _T] = ...) -> Union[_T, _D]: ...
20+
def items(self) -> Iterator[Tuple[str, Optional[str]]]: ...
21+
def lineof(self, name: str) -> Optional[int]: ...
22+
23+
class IniConfig:
24+
path: Final[str]
25+
sections: Final[Mapping[str, Mapping[str, Optional[str]]]]
26+
def __init__(self, path: str, data: Optional[str] = None): ...
27+
def __contains__(self, arg: str) -> bool: ...
28+
def __getitem__(self, name: str) -> _SectionWrapper: ...
29+
def __iter__(self) -> Iterator[_SectionWrapper]: ...
30+
def get(self, section: str, name: str, default: _D = ..., convert: Callable[[Optional[str]], _T] = ...) -> Union[_T, _D]: ...
31+
def lineof(self, section: str, name: Optional[str] = ...) -> Optional[int]: ...

py/io.pyi

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
from io import StringIO as TextIO
2+
from io import BytesIO as BytesIO
3+
from typing import Any, AnyStr, Callable, Generic, IO, List, Optional, Text, Tuple, TypeVar, Union, overload
4+
from typing_extensions import Final
5+
import sys
6+
7+
_T = TypeVar("_T")
8+
9+
class FDCapture(Generic[AnyStr]):
10+
def __init__(self, targetfd: int, tmpfile: Optional[IO[AnyStr]] = ..., now: bool = ..., patchsys: bool = ...) -> None: ...
11+
def start(self) -> None: ...
12+
def done(self) -> IO[AnyStr]: ...
13+
def writeorg(self, data: AnyStr) -> None: ...
14+
15+
class StdCaptureFD:
16+
def __init__(
17+
self,
18+
out: Union[bool, IO[str]] = ...,
19+
err: Union[bool, IO[str]] = ...,
20+
mixed: bool = ...,
21+
in_: bool = ...,
22+
patchsys: bool = ...,
23+
now: bool = ...,
24+
) -> None: ...
25+
@classmethod
26+
def call(cls, func: Callable[..., _T], *args: Any, **kwargs: Any) -> Tuple[_T, str, str]: ...
27+
def reset(self) -> Tuple[str, str]: ...
28+
def suspend(self) -> Tuple[str, str]: ...
29+
def startall(self) -> None: ...
30+
def resume(self) -> None: ...
31+
def done(self, save: bool = ...) -> Tuple[IO[str], IO[str]]: ...
32+
def readouterr(self) -> Tuple[str, str]: ...
33+
34+
class StdCapture:
35+
def __init__(
36+
self,
37+
out: Union[bool, IO[str]] = ...,
38+
err: Union[bool, IO[str]] = ...,
39+
in_: bool = ...,
40+
mixed: bool = ...,
41+
now: bool = ...,
42+
) -> None: ...
43+
@classmethod
44+
def call(cls, func: Callable[..., _T], *args: Any, **kwargs: Any) -> Tuple[_T, str, str]: ...
45+
def reset(self) -> Tuple[str, str]: ...
46+
def suspend(self) -> Tuple[str, str]: ...
47+
def startall(self) -> None: ...
48+
def resume(self) -> None: ...
49+
def done(self, save: bool = ...) -> Tuple[IO[str], IO[str]]: ...
50+
def readouterr(self) -> Tuple[IO[str], IO[str]]: ...
51+
52+
# XXX: The type here is not exactly right. If f is IO[bytes] and
53+
# encoding is not None, returns some weird hybrid, not exactly IO[bytes].
54+
def dupfile(
55+
f: IO[AnyStr],
56+
mode: Optional[str] = ...,
57+
buffering: int = ...,
58+
raising: bool = ...,
59+
encoding: Optional[str] = ...,
60+
) -> IO[AnyStr]: ...
61+
def get_terminal_width() -> int: ...
62+
def ansi_print(
63+
text: Union[str, Text],
64+
esc: Union[Union[str, Text], Tuple[Union[str, Text], ...]],
65+
file: Optional[IO[Any]] = ...,
66+
newline: bool = ...,
67+
flush: bool = ...,
68+
) -> None: ...
69+
def saferepr(obj, maxsize: int = ...) -> str: ...
70+
71+
class TerminalWriter:
72+
stringio: TextIO
73+
encoding: Final[str]
74+
hasmarkup: bool
75+
def __init__(self, file: Optional[IO[str]] = ..., stringio: bool = ..., encoding: Optional[str] = ...) -> None: ...
76+
@property
77+
def fullwidth(self) -> int: ...
78+
@fullwidth.setter
79+
def fullwidth(self, value: int) -> None: ...
80+
@property
81+
def chars_on_current_line(self) -> int: ...
82+
@property
83+
def width_of_current_line(self) -> int: ...
84+
def markup(
85+
self,
86+
text: str,
87+
*,
88+
black: int = ..., red: int = ..., green: int = ..., yellow: int = ..., blue: int = ..., purple: int = ...,
89+
cyan: int = ..., white: int = ..., Black: int = ..., Red: int = ..., Green: int = ..., Yellow: int = ...,
90+
Blue: int = ..., Purple: int = ..., Cyan: int = ..., White: int = ..., bold: int = ..., light: int = ...,
91+
blink: int = ..., invert: int = ...,
92+
) -> str: ...
93+
def sep(
94+
self,
95+
sepchar: str,
96+
title: Optional[str] = ...,
97+
fullwidth: Optional[int] = ...,
98+
*,
99+
black: int = ..., red: int = ..., green: int = ..., yellow: int = ..., blue: int = ..., purple: int = ...,
100+
cyan: int = ..., white: int = ..., Black: int = ..., Red: int = ..., Green: int = ..., Yellow: int = ...,
101+
Blue: int = ..., Purple: int = ..., Cyan: int = ..., White: int = ..., bold: int = ..., light: int = ...,
102+
blink: int = ..., invert: int = ...,
103+
) -> None: ...
104+
def write(
105+
self,
106+
msg: str,
107+
*,
108+
black: int = ..., red: int = ..., green: int = ..., yellow: int = ..., blue: int = ..., purple: int = ...,
109+
cyan: int = ..., white: int = ..., Black: int = ..., Red: int = ..., Green: int = ..., Yellow: int = ...,
110+
Blue: int = ..., Purple: int = ..., Cyan: int = ..., White: int = ..., bold: int = ..., light: int = ...,
111+
blink: int = ..., invert: int = ...,
112+
) -> None: ...
113+
def line(
114+
self,
115+
s: str = ...,
116+
*,
117+
black: int = ..., red: int = ..., green: int = ..., yellow: int = ..., blue: int = ..., purple: int = ...,
118+
cyan: int = ..., white: int = ..., Black: int = ..., Red: int = ..., Green: int = ..., Yellow: int = ...,
119+
Blue: int = ..., Purple: int = ..., Cyan: int = ..., White: int = ..., bold: int = ..., light: int = ...,
120+
blink: int = ..., invert: int = ...,
121+
) -> None: ...
122+
def reline(
123+
self,
124+
line: str,
125+
*,
126+
black: int = ..., red: int = ..., green: int = ..., yellow: int = ..., blue: int = ..., purple: int = ...,
127+
cyan: int = ..., white: int = ..., Black: int = ..., Red: int = ..., Green: int = ..., Yellow: int = ...,
128+
Blue: int = ..., Purple: int = ..., Cyan: int = ..., White: int = ..., bold: int = ..., light: int = ...,
129+
blink: int = ..., invert: int = ...,
130+
) -> None: ...

0 commit comments

Comments
 (0)