Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fd005b

Browse files
TeamSpen210A5rocks
andauthored
Define types for AsyncIOWrapper and trio.Path (#2706)
* Add types to directly defined objects in _file_io * Implement methods on AsyncIOWrapper using a pile of self-type-properties. * Add types for open_file() * Suppress the duplicate type hints for trio.open_file() * Add types to Path wrapper class * Overloads are never executed, so they should be ignored by coverage * Type trio._util.async_wraps * Add mostly-any types for internal _path functions These are way too dynamic to properly type. * Disallow untyped definitions in _path and _file_io --------- Co-authored-by: EXPLOSION <[email protected]>
1 parent e545484 commit 2fd005b

File tree

9 files changed

+690
-158
lines changed

9 files changed

+690
-158
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exclude_lines =
2121
abc.abstractmethod
2222
if TYPE_CHECKING:
2323
if _t.TYPE_CHECKING:
24+
@overload
2425

2526
partial_branches =
2627
pragma: no branch

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
("py:obj", "trio._abc.T"),
6464
("py:obj", "trio._abc.T_resource"),
6565
("py:class", "types.FrameType"),
66+
("py:class", "P.args"),
67+
("py:class", "P.kwargs"),
6668
# TODO: figure out if you can link this to SSL
6769
("py:class", "Context"),
6870
# TODO: temporary type

docs/source/reference-io.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,11 @@ Asynchronous path objects
637637
Asynchronous file objects
638638
~~~~~~~~~~~~~~~~~~~~~~~~~
639639

640-
.. autofunction:: open_file
640+
.. Suppress type annotations here, they refer to lots of internal types.
641+
The normal Python docs go into better detail.
642+
.. autofunction:: open_file(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=None, opener=None)
641643

642-
.. autofunction:: wrap_file
644+
.. autofunction:: wrap_file(file)
643645

644646
.. interface:: Asynchronous file interface
645647

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ disallow_untyped_defs = false
4646

4747
# DO NOT use `ignore_errors`; it doesn't apply
4848
# downstream and users have to deal with them.
49+
[[tool.mypy.overrides]]
50+
module = [
51+
"trio._path",
52+
"trio._file_io",
53+
]
54+
disallow_untyped_defs = true
4955

5056
[[tool.mypy.overrides]]
5157
module = [

0 commit comments

Comments
 (0)