Skip to content

Commit 7aabf2e

Browse files
tomwatson1024Tom W
and
Tom W
authored
Add type hints and py.typed marker file
Co-authored-by: Tom W <[email protected]>
1 parent 4eeadd5 commit 7aabf2e

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

.mypy.ini

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[mypy]
2+
# Error codes can be used to write more specific `type: ignore` comments.
3+
show_error_codes = True
4+
5+
[mypy-curio.*]
6+
# Curio doesn't provide type hints.
7+
ignore_missing_imports = True
8+
9+
[mypy-pytest.*]
10+
# The version of pytest used doesn't provide type hints.
11+
ignore_missing_imports = True

ci/travis.sh

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -ex
44

5+
MYPY_VERSION=0.782
56
YAPF_VERSION=0.22.0
67

78
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
@@ -75,6 +76,19 @@ in your local checkout.
7576
EOF
7677
exit 1
7778
fi
79+
pip install mypy==${MYPY_VERSION}
80+
if ! mypy --pretty sniffio; then
81+
cat <<EOF
82+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
83+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
84+
85+
Type checking problems were found (listed above).
86+
87+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
88+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
89+
EOF
90+
exit 1
91+
fi
7892
exit 0
7993
fi
8094

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
author_email="[email protected]",
1515
license="MIT -or- Apache License 2.0",
1616
packages=find_packages(),
17+
package_data={"sniffio": ["py.typed"]},
1718
install_requires=[],
1819
keywords=[
1920
"async",

sniffio/_impl.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from contextvars import ContextVar
2+
from typing import Optional
23
import sys
34

45
current_async_library_cvar = ContextVar(
56
"current_async_library_cvar", default=None
6-
)
7+
) # type: ContextVar[Optional[str]]
78

89

910
class AsyncLibraryNotFoundError(RuntimeError):
1011
pass
1112

1213

13-
def current_async_library():
14+
def current_async_library() -> str:
1415
"""Detect which async library is currently running.
1516
1617
The following libraries are currently supported:
@@ -65,9 +66,9 @@ async def generic_sleep(seconds):
6566
if "asyncio" in sys.modules:
6667
import asyncio
6768
try:
68-
current_task = asyncio.current_task
69+
current_task = asyncio.current_task # type: ignore[attr-defined]
6970
except AttributeError:
70-
current_task = asyncio.Task.current_task
71+
current_task = asyncio.Task.current_task # type: ignore[attr-defined]
7172
try:
7273
if current_task() is not None:
7374
if (3, 7) <= sys.version_info:

sniffio/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)