From 009c07573eebc346815d4f32d5b4a1b86bbcb246 Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Thu, 16 Dec 2021 14:36:42 -0700 Subject: [PATCH 1/2] Add support for mypy 0.920 --- README.rst | 2 ++ ci.sh | 2 +- setup.py | 2 +- trio-stubs/__init__.pyi | 4 +--- trio_typing/plugin.py | 23 ++++++++++------------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index 2f1443b..0a70f1b 100644 --- a/README.rst +++ b/README.rst @@ -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] diff --git a/ci.sh b/ci.sh index 27416b4..8d354eb 100755 --- a/ci.sh +++ b/ci.sh @@ -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 diff --git a/setup.py b/setup.py index 87e8884..ff0fb6b 100644 --- a/setup.py +++ b/setup.py @@ -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"], diff --git a/trio-stubs/__init__.pyi b/trio-stubs/__init__.pyi index 020bd97..17fa165 100644 --- a/trio-stubs/__init__.pyi +++ b/trio-stubs/__init__.pyi @@ -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 diff --git a/trio_typing/plugin.py b/trio_typing/plugin.py index d956672..edc2059 100644 --- a/trio_typing/plugin.py +++ b/trio_typing/plugin.py @@ -18,8 +18,7 @@ CallableType, NoneTyp, Overloaded, - TypeVarDef, - TypeVarLikeDef, + TypeVarLikeType, TypeVarType, Instance, UnionType, @@ -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=( @@ -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=( @@ -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: From e158eec1141785eea6adf576819c257cd0864d12 Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Thu, 16 Dec 2021 14:49:05 -0700 Subject: [PATCH 2/2] Remove some socket constants that seem to have been removed from typeshed --- trio-stubs/socket.pyi | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/trio-stubs/socket.pyi b/trio-stubs/socket.pyi index b707e82..56e4807 100644 --- a/trio-stubs/socket.pyi +++ b/trio-stubs/socket.pyi @@ -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, @@ -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, @@ -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, @@ -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,