Skip to content

Commit e19af18

Browse files
authored
Merge branch 'master' into limit-isort
2 parents 417a10b + 532bbd8 commit e19af18

File tree

18 files changed

+466
-63
lines changed

18 files changed

+466
-63
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313

1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717
- name: Setup python
18-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v4
1919
with:
2020
python-version: ${{ matrix.python }}
2121
cache: pip
@@ -43,9 +43,9 @@ jobs:
4343
extra_name: ', check formatting'
4444
steps:
4545
- name: Checkout
46-
uses: actions/checkout@v2
46+
uses: actions/checkout@v4
4747
- name: Setup python
48-
uses: actions/setup-python@v2
48+
uses: actions/setup-python@v4
4949
if: "!endsWith(matrix.python, '-dev')"
5050
with:
5151
python-version: ${{ matrix.python }}
@@ -73,9 +73,9 @@ jobs:
7373
python: ['3.7', '3.8', '3.9', '3.10']
7474
steps:
7575
- name: Checkout
76-
uses: actions/checkout@v2
76+
uses: actions/checkout@v4
7777
- name: Setup python
78-
uses: actions/setup-python@v2
78+
uses: actions/setup-python@v4
7979
with:
8080
python-version: ${{ matrix.python }}
8181
cache: pip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ htmlcov/
3939
.coverage.*
4040
.cache
4141
.pytest_cache
42+
.mypy_cache
4243
nosetests.xml
4344
coverage.xml
4445

.readthedocs.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
version: 2
2+
13
# https://docs.readthedocs.io/en/latest/yaml-config.html
24
formats:
35
- htmlzip
46
- epub
57

6-
requirements_file: ci/rtd-requirements.txt
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3"
712

813
python:
9-
version: 3
10-
pip_install: True
14+
install:
15+
- requirements: ci/rtd-requirements.txt
16+
- method: pip
17+
path: .

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include README.rst CHEATSHEET.rst LICENSE* CODE_OF_CONDUCT* CONTRIBUTING*
22
include .coveragerc .style.yapf
33
include test-requirements.txt
4+
include src/outcome/py.typed
45
recursive-include docs *
56
prune docs/build
67
recursive-include tests *.py

ci.sh

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ set -ex
55
CHECK_FILES="setup.py src tests"
66
YAPF_VERSION=0.20.1
77

8-
pip install -U pip setuptools wheel
8+
python -m pip install -U pip setuptools wheel
99

1010
python setup.py sdist --formats=zip
1111
pip install dist/*.zip
1212

13+
# Install dependencies.
14+
pip install -Ur test-requirements.txt
15+
1316
if [ "$CHECK_FORMATTING" = "1" ]; then
14-
pip install yapf==${YAPF_VERSION} "isort>=5"
17+
pip install yapf==${YAPF_VERSION} "isort>=5" mypy pyright
1518
if ! yapf -rpd $CHECK_FILES; then
1619
cat <<EOF
1720
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -30,9 +33,6 @@ EOF
3033
exit 1
3134
fi
3235

33-
# required for isort to order test imports correctly
34-
pip install -Ur test-requirements.txt
35-
3636
if ! isort --check-only --diff $CHECK_FILES ; then
3737
cat <<EOF
3838
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -50,12 +50,46 @@ in your local checkout.
5050
EOF
5151
exit 1
5252
fi
53+
54+
if ! mypy src/ tests/type_tests.py ; then
55+
cat <<EOF
56+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
57+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58+
59+
Type checking errors were found (listed above). To get more detail, run
60+
61+
pip install mypy
62+
mypy src/ tests/type_tests.py
63+
64+
in your local checkout.
65+
66+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
68+
EOF
69+
exit 1
70+
fi
71+
72+
if ! pyright --verifytypes outcome src/outcome/ ; then
73+
cat <<EOF
74+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76+
77+
Types are not complete (listed above). To get more detail, run
78+
79+
pip install pyright
80+
pyright --verifytypes outcome src/outcome/
81+
82+
in your local checkout.
83+
84+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
85+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
86+
EOF
87+
exit 1
88+
fi
89+
5390
exit 0
5491
fi
5592

56-
# Actual tests
57-
pip install -Ur test-requirements.txt
58-
5993
pytest -W error -ra -v tests --cov --cov-config=.coveragerc
6094

6195
bash <(curl -s https://codecov.io/bash)

ci/rtd-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# RTD is currently installing 1.5.3, which has a bug in :lineno-match:
2-
sphinx >= 1.6.1
2+
sphinx >= 4.0, < 6.2
33
sphinx_rtd_theme
44
sphinxcontrib-trio

docs/source/api.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ API Reference
1414
:members:
1515
:inherited-members:
1616

17+
.. py:data:: Maybe
18+
:value: Value[ResultT] | Error
19+
20+
A convenience alias to a union of both results. This allows type checkers to perform
21+
exhaustiveness checking when ``isinstance()`` is used with either class::
22+
23+
outcome: Maybe[int] = capture(some_function, 1, 2, 3)
24+
if isinstance(outcome, Value):
25+
# Type checkers know it's a Value[int] here.
26+
else:
27+
# It must be an Error.
28+
1729
.. autoclass:: Value
1830
:members:
1931
:inherited-members:

docs/source/conf.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#
1919
import os
2020
import sys
21+
2122
# So autodoc can import our package
2223
sys.path.insert(0, os.path.abspath('../..'))
2324

@@ -27,6 +28,13 @@
2728
nitpick_ignore = [
2829
# Format is ('sphinx reference type', 'string'), e.g.:
2930
('py:obj', 'bytes-like'),
31+
# Typevars aren't found, for some reason.
32+
('py:class', 'ArgsT'),
33+
('py:class', 'ArgsT.args'),
34+
('py:class', 'ArgsT.kwargs'),
35+
('py:class', 'ResultT'),
36+
('py:class', 'outcome._impl.ResultT'),
37+
('py:class', 'outcome._impl.ValueT'),
3038
]
3139

3240
# -- General configuration ------------------------------------------------
@@ -76,6 +84,7 @@
7684
#
7785
# The short X.Y version.
7886
import outcome
87+
7988
version = outcome.__version__
8089
# The full version, including alpha/beta/rc tags.
8190
release = version
@@ -101,7 +110,6 @@
101110
# If true, `todo` and `todoList` produce output, else they produce nothing.
102111
todo_include_todos = False
103112

104-
105113
# -- Options for HTML output ----------------------------------------------
106114

107115
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -113,6 +121,7 @@
113121
# testing, but also because if we don't then RTD will throw away our
114122
# html_theme_options.
115123
import sphinx_rtd_theme
124+
116125
html_theme = 'sphinx_rtd_theme'
117126
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
118127

@@ -135,13 +144,11 @@
135144
# so a file named 'default.css' will overwrite the builtin 'default.css'.
136145
html_static_path = ['_static']
137146

138-
139147
# -- Options for HTMLHelp output ------------------------------------------
140148

141149
# Output file base name for HTML help builder.
142150
htmlhelp_basename = 'outcomedoc'
143151

144-
145152
# -- Options for LaTeX output ---------------------------------------------
146153

147154
latex_elements = {
@@ -166,28 +173,23 @@
166173
# (source start file, target name, title,
167174
# author, documentclass [howto, manual, or own class]).
168175
latex_documents = [
169-
(master_doc, 'outcome.tex', 'Trio Documentation',
170-
author, 'manual'),
176+
(master_doc, 'outcome.tex', 'Trio Documentation', author, 'manual'),
171177
]
172178

173-
174179
# -- Options for manual page output ---------------------------------------
175180

176181
# One entry per manual page. List of tuples
177182
# (source start file, name, description, authors, manual section).
178-
man_pages = [
179-
(master_doc, 'outcome', 'outcome Documentation',
180-
[author], 1)
181-
]
182-
183+
man_pages = [(master_doc, 'outcome', 'outcome Documentation', [author], 1)]
183184

184185
# -- Options for Texinfo output -------------------------------------------
185186

186187
# Grouping the document tree into Texinfo files. List of tuples
187188
# (source start file, target name, title, author,
188189
# dir menu entry, description, category)
189190
texinfo_documents = [
190-
(master_doc, 'outcome', 'outcome Documentation',
191-
author, 'outcome', 'Capture the outcome of Python function call.',
192-
'Miscellaneous'),
191+
(
192+
master_doc, 'outcome', 'outcome Documentation', author, 'outcome',
193+
'Capture the outcome of Python function call.', 'Miscellaneous'
194+
),
193195
]

docs/source/history.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ Release history
55

66
.. towncrier release notes start
77
8+
Outcome 1.3.0 (2023-10-17)
9+
--------------------------
10+
11+
Features
12+
~~~~~~~~
13+
14+
- Added type hints to the package. :py:class:`Value` and :py:class:`Outcome` are now generic.
15+
A type alias was also added (:py:data:`Maybe`) for the union of :py:class:`Value`
16+
and :py:class:`Error`. (`#36 <https://github.com/python-trio/outcome/issues/36>`__)
17+
18+
819
Outcome 1.2.0 (2022-06-14)
920
--------------------------
1021

pyproject.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,33 @@ filename = "docs/source/history.rst"
44
directory = "newsfragments"
55
underlines = ["-", "~", "^"]
66
issue_format = "`#{issue} <https://github.com/python-trio/outcome/issues/{issue}>`__"
7+
8+
[tool.isort]
9+
combine_as_imports = true
10+
profile = "black"
11+
skip_gitignore = true
12+
13+
[tool.mypy]
14+
# Be strict about use of Mypy
15+
strict = true
16+
warn_unused_ignores = true
17+
warn_unused_configs = true
18+
warn_redundant_casts = true
19+
warn_no_return = true
20+
warn_unreachable = true
21+
warn_return_any = true
22+
23+
# Avoid subtle backsliding
24+
disallow_incomplete_defs = true
25+
disallow_subclassing_any = true
26+
disallow_any_unimported = true
27+
disallow_any_generics = true
28+
disallow_any_explicit = false
29+
30+
check_untyped_defs = true
31+
disallow_untyped_calls = true
32+
disallow_untyped_defs = true
33+
disallow_untyped_decorators = true
34+
35+
# DO NOT use `ignore_errors`; it doesn't apply
36+
# downstream and users have to deal with them.

0 commit comments

Comments
 (0)