Skip to content

Commit

Permalink
Merge pull request #52 from oremanj/support-mypy-0.920
Browse files Browse the repository at this point in the history
Add support for mypy 0.920
  • Loading branch information
tjstum authored Dec 16, 2021
2 parents aed1e7d + e158eec commit 480c884
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 50 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Install trio-typing with mypy extras::

pip install trio-typing[mypy]

Note that due to recent plugin API changes, trio-typing 0.7.0+ requires mypy 0.920+.

Enable the plugin in your ``mypy.ini``::

[mypy]
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex -o pipefail

BLACK_VERSION=19.10b0
MYPY_VERSION=0.910
MYPY_VERSION=0.920

pip install -U pip setuptools wheel

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
extras_require={
"mypy": [ # can't be installed on PyPy due to its dependency on typed-ast
"mypy >= 0.780",
"mypy >= 0.920",
],
},
keywords=["async", "trio", "mypy"],
Expand Down
4 changes: 1 addition & 3 deletions trio-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ from typing import (
overload,
)

# TODO: change this to 'import StrOrBytesPath' once mypy release picks up
# https://github.com/python/typeshed/commit/f0bf6eebbde0f779666f17e258fceb78dbb7f9d5
from _typeshed import AnyPath as StrOrBytesPath
from _typeshed import StrOrBytesPath
from _typeshed import OpenBinaryMode, OpenTextMode, ReadableBuffer, WriteableBuffer
from trio_typing import TaskStatus, takes_callable_and_args
from typing_extensions import Protocol, Literal
Expand Down
32 changes: 0 additions & 32 deletions trio-stubs/socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ from socket import (
AI_PASSIVE as AI_PASSIVE,
AI_V4MAPPED as AI_V4MAPPED,
AI_V4MAPPED_CFG as AI_V4MAPPED_CFG,
BDADDR_ANY as BDADDR_ANY,
BDADDR_LOCAL as BDADDR_LOCAL,
BTPROTO_HCI as BTPROTO_HCI,
BTPROTO_L2CAP as BTPROTO_L2CAP,
BTPROTO_RFCOMM as BTPROTO_RFCOMM,
BTPROTO_SCO as BTPROTO_SCO,
CAN_EFF_FLAG as CAN_EFF_FLAG,
CAN_EFF_MASK as CAN_EFF_MASK,
CAN_ERR_FLAG as CAN_ERR_FLAG,
Expand Down Expand Up @@ -100,12 +94,6 @@ from socket import (
EAI_SERVICE as EAI_SERVICE,
EAI_SOCKTYPE as EAI_SOCKTYPE,
EAI_SYSTEM as EAI_SYSTEM,
EBADF as EBADF,
EINTR as EINTR,
EWOULDBLOCK as EWOULDBLOCK,
HCI_DATA_DIR as HCI_DATA_DIR,
HCI_FILTER as HCI_FILTER,
HCI_TIME_STAMP as HCI_TIME_STAMP,
INADDR_ALLHOSTS_GROUP as INADDR_ALLHOSTS_GROUP,
INADDR_ANY as INADDR_ANY,
INADDR_BROADCAST as INADDR_BROADCAST,
Expand Down Expand Up @@ -216,20 +204,6 @@ from socket import (
MSG_PEEK as MSG_PEEK,
MSG_TRUNC as MSG_TRUNC,
MSG_WAITALL as MSG_WAITALL,
NETLINK_ARPD as NETLINK_ARPD,
NETLINK_CRYPTO as NETLINK_CRYPTO,
NETLINK_DNRTMSG as NETLINK_DNRTMSG,
NETLINK_FIREWALL as NETLINK_FIREWALL,
NETLINK_IP6_FW as NETLINK_IP6_FW,
NETLINK_NFLOG as NETLINK_NFLOG,
NETLINK_ROUTE6 as NETLINK_ROUTE6,
NETLINK_ROUTE as NETLINK_ROUTE,
NETLINK_SKIP as NETLINK_SKIP,
NETLINK_TAPBASE as NETLINK_TAPBASE,
NETLINK_TCPDIAG as NETLINK_TCPDIAG,
NETLINK_USERSOCK as NETLINK_USERSOCK,
NETLINK_W1 as NETLINK_W1,
NETLINK_XFRM as NETLINK_XFRM,
NI_DGRAM as NI_DGRAM,
NI_MAXHOST as NI_MAXHOST,
NI_MAXSERV as NI_MAXSERV,
Expand Down Expand Up @@ -366,12 +340,6 @@ from socket import (

if sys.version_info >= (3, 6):
from socket import (
SO_DOMAIN as SO_DOMAIN,
SO_PROTOCOL as SO_PROTOCOL,
SO_PEERSEC as SO_PEERSEC,
SO_PASSSEC as SO_PASSSEC,
TCP_USER_TIMEOUT as TCP_USER_TIMEOUT,
TCP_CONGESTION as TCP_CONGESTION,
AF_ALG as AF_ALG,
SOL_ALG as SOL_ALG,
ALG_SET_KEY as ALG_SET_KEY,
Expand Down
23 changes: 10 additions & 13 deletions trio_typing/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
CallableType,
NoneTyp,
Overloaded,
TypeVarDef,
TypeVarLikeDef,
TypeVarLikeType,
TypeVarType,
Instance,
UnionType,
Expand Down Expand Up @@ -445,14 +444,13 @@ def start_soon(
)

expanded_fns = [] # type: List[CallableType]
type_var_defs = [] # type: List[TypeVarDef]
type_var_types = [] # type: List[Type]
type_var_types = [] # type: List[TypeVarType]
for arg_idx in range(1, 7): # provides overloads for 0 through 5 arguments
arg_types = list(fn_type.arg_types)
arg_types[callable_idx] = callable_ty.copy_modified(
arg_types=(
callable_ty.arg_types[:callable_args_idx]
+ type_var_types
+ cast(List[Type], type_var_types)
+ callable_ty.arg_types[callable_args_idx + 1 :]
),
arg_kinds=(
Expand All @@ -467,14 +465,14 @@ def start_soon(
),
variables=(
list(callable_ty.variables)
+ cast(List[TypeVarLikeDef], type_var_defs)
+ cast(List[TypeVarLikeType], type_var_types)
),
)
expanded_fns.append(
fn_type.copy_modified(
arg_types=(
arg_types[:args_idx]
+ type_var_types
+ cast(List[Type], type_var_types)
+ arg_types[args_idx + 1 :]
),
arg_kinds=(
Expand All @@ -489,22 +487,21 @@ def start_soon(
),
variables=(
list(fn_type.variables)
+ cast(List[TypeVarLikeDef], type_var_defs)
+ cast(List[TypeVarLikeType], type_var_types)
),
)
)
type_var_defs.append(
TypeVarDef(
type_var_types.append(
TypeVarType(
"__T{}".format(arg_idx),
"__T{}".format(arg_idx),
-len(fn_type.variables) - arg_idx - 1,
[],
ctx.api.named_generic_type("builtins.object", []),
line=ctx.context.line,
column=ctx.context.column,
)
)
type_var_types.append(
TypeVarType(type_var_defs[-1], ctx.context.line, ctx.context.column)
)
return Overloaded(expanded_fns)

except ValueError as ex:
Expand Down

0 comments on commit 480c884

Please sign in to comment.