From e938f7f02aeb1de26483016f0a61310c909833d6 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Mon, 28 Aug 2017 15:29:18 -0700 Subject: [PATCH 01/12] Add definitions for boto.utils.pythonize_name --- third_party/2and3/boto/utils.pyi | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 third_party/2and3/boto/utils.pyi diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi new file mode 100644 index 000000000000..075ad33c9211 --- /dev/null +++ b/third_party/2and3/boto/utils.pyi @@ -0,0 +1,3 @@ +from typing import Text + +def pythonize_name(name: Text) -> Text: ... From a3e45b5693cd34e5c6fd362046ebcb9d7d0b1d22 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 29 Aug 2017 17:41:05 -0700 Subject: [PATCH 02/12] Add stubs for provider.pyi and utils.pyi --- third_party/2and3/boto/provider.pyi | 111 +++++++++++++++ third_party/2and3/boto/utils.pyi | 200 +++++++++++++++++++++++++++- 2 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 third_party/2and3/boto/provider.pyi diff --git a/third_party/2and3/boto/provider.pyi b/third_party/2and3/boto/provider.pyi new file mode 100644 index 000000000000..f90fc5ef9294 --- /dev/null +++ b/third_party/2and3/boto/provider.pyi @@ -0,0 +1,111 @@ +from typing import Any, Optional, Text, Union + +from boto.exceptions import BotoServerError +from boto.gs.acl import CannedACLStrings as CannedGSACLStrings +from boto.pyami.config import Config +from boto.s3.acl import Acl, Policy +from boto.s3.acl import CannedACLStrings as CannedS3ACLStrings + +HEADER_PREFIX_KEY = ... # type: Text +METADATA_PREFIX_KEY = ... # type: Text +AWS_HEADER_PREFIX = ... # type: Text +GOOG_HEADER_PREFIX = ... # type: Text +ACL_HEADER_KEY = ... # type: Text +AUTH_HEADER_KEY = ... # type: Text +COPY_SOURCE_HEADER_KEY = ... # type: Text +COPY_SOURCE_VERSION_ID_HEADER_KEY = ... # type: Text +COPY_SOURCE_RANGE_HEADER_KEY = ... # type: Text +DELETE_MARKER_HEADER_KEY = ... # type: Text +DATE_HEADER_KEY = ... # type: Text +METADATA_DIRECTIVE_HEADER_KEY = ... # type: Text +RESUMABLE_UPLOAD_HEADER_KEY = ... # type: Text +SECURITY_TOKEN_HEADER_KEY = ... # type: Text +STORAGE_CLASS_HEADER_KEY = ... # type: Text +MFA_HEADER_KEY = ... # type: Text +SERVER_SIDE_ENCRYPTION_KEY = ... # type: Text +VERSION_ID_HEADER_KEY = ... # type: Text +RESTORE_HEADER_KEY = ... # type: Text +STORAGE_COPY_ERROR = ... # type: Text +STORAGE_CREATE_ERROR = ... # type: Text +STORAGE_DATA_ERROR = ... # type: Text +STORAGE_PERMISSIONS_ERROR = ... # type: Text +STORAGE_RESPONSE_ERROR = ... # type: Text +NO_CREDENTIALS_PROVIDED = ... # type: object + +class ProfileNotFoundError(ValueError): ... + +class Provider: + CredentialMap = ... # type: Dict[Text, Tuple[Text, Text, Text, Text] + AclClassMap = ... # type: Dict[Text, Union[Policy, Acl]] + CannedAclsMap = ... # type: Dict[Text, Union[CannedS3ACLStrings, CannedGSACLStrings]] + HostKeyMap = ... # type: Dict[Text, Text] + ChunkedTransferSupport = ... # type: Dict[Text, bool] + MetadataServiceSupport = ... # type: Dict[Text, bool] + HeaderInfoMap = ... # type: Dict[Text, Dict[Text, Optional[Text]]] + ErrorMap = ... # type: Dict[Text, BotoServerError] + + host = ... # type: Optional[Text] + port = ... # type: Optional[int] + host_header = ... # type: Optional[Text] + access_key = ... # type: Text + secret_key = ... # type: Text + security_token = ... # type: Optional[Text] + profile_name = ... # type: Optional[Text] + name = ... # type: Text + acl_class = ... # type: Union[Policy, Acl] + canned_acls = ... # type: Union[CannedS3ACLStrings, CannedGSACLStrings] + shared_credentials = ... # type: Any + + def __init__( + self, + name: Text, + access_key: Optional[Text] = ..., + secret_key: Optional[Text] = ..., + security_token: Optional[Text] = ..., + profile_name: Optional[Text] = ..., + ): ... + def get_access_key(self): ... + def set_access_key(self, value: Text): ... + def get_secret_key(self): ... + def set_secret_key(self, value: Text): ... + def get_security_token(self): ... + def set_security_token(self, value: Text): ... + def get_credentials( + self, + access_key: Optional[Text] = ..., + secret_key: Optional[Text] = ..., + security_token: Optional[Text] = ..., + profile_name: Optional[Text] = ..., + ):... + + metadata_prefix = ... # type: Text + header_prefix = ... # type: Text + acl_header = ... # type: Text + auth_header = ... # type: Text + copy_source_header = ... # type: Text + copy_source_version_id = ... # type: Text + copy_source_range_header = ... # type: Optional[Text] + date_header = ... # type: Text + delete_marker = ... # type: Text + metadata_directive_header = ... # type: Text + security_token_header = ... # type: Text + resumable_upload_header = ... # type: Optional[Text] + server_side_encryption_header = ... # type: Optional[Text] + storage_class_header = ... # type: Text + version_id = ... # type: Text + mfa_header = ... # type: Optional[Text] + restore_header = ... # type: Optional[Text] + + def configure_headers(self): ... + + storage_copy_error = ... # type: BotoServerError + storage_create_error = ... # type: BotoServerError + storage_data_error = ... # type: BotoServerError + storage_permissions_error = ... # type: BotoServerError + storage_response_error = ... # type: BotoServerError + + def configure_errors(self): ... + def get_provider_name(self) -> Text: ... + def supports_chunked_transfer(self) -> bool: ... + +def get_default() -> Provider: ... diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 075ad33c9211..e16c08d899c1 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -1,3 +1,201 @@ -from typing import Text +import logging +import logging.handlers +import datetime +import subprocess +import thread +import time +import boto.provider +import boto.connection +import six +from typing import Any, List, Hashable, Optional, Text, Union, Tuple + + +JSONDecodeError = ... # type: Exception +qsa_of_interest = ... # type: List[Text] + +def unquote_v(nv: Text) -> Union[Text, Tuple[Text, Text]]: ... +def canonical_string( + method: Text, + path: Text, + headers: Dict[Text, Text], + expires: Optional[int] = ..., + provider: Optional[boto.provider.Provider] = ..., +): ... +def merge_meta( + headers: Dict[Text, Text], + metadata: Dict[Text, Text], + provider: Optional[boto.provider.Provider] = ..., +): ... +def get_aws_metadata(headers: Dict[Text, Text], provider: Optional[boto.provider.Provider] = ...): ... +def retry_url( + url: Text, + retry_on_404: bool = ..., + num_retries: int = ..., + timeout: Optional[int] = ..., +): ... + +class LazyLoadMetadata(dict): + def __init__( + self, + url: Text, + num_retries: int, + timeout: Optional[int] = ..., + ) -> None: ... + def __getitem__(self, key: Hashable): ... + def get(self, key: Hashable, default: Optional[Any] = ...) -> Any: ... + def values(self) -> List[Any]: ... + def items(self) -> List[Tuple[Any, Any]]: ... + +def get_instance_metadata( + version: Text = ..., + url: Text = ..., + data: Text = ..., + timeout: Optional[int] = ..., + num_retries: int = ... +) -> Optional[LazyLoadMetadata]: ... +def get_instance_identity( + version: Text = ..., + url: Text = ..., + timeout: Optional[int] = ..., + num_retries: int = ..., +) -> Optional[Dict[Text, Any]]: ... +def get_instance_userdata( + version: Text = ..., + sep: Optional[Text] = ..., + url: Text = ..., + timeout: Optional[int] = ..., + num_retries: int = ..., +) -> Dict[Text, Text]: ... + +ISO8601 = ... # type: Text +ISO8601_MS = ... # type: Text +RFC1123 = ... # type: Text +LOCALE_LOCK = ... # type: therad.LockType + +def setlocale(name: Union[Text, Tuple[Text, Text]]): ... +def get_ts(ts: Optional[time.struct_time] = ...) -> Text: ... +def parse_ts(ts: Text) -> datetime.datetime: ... +def find_class(module_name: Text, class_name: Optional[Text] = ...) -> Optional[Any]: ... +def update_dme(username: Text, password: Text, dme_id: Text, ip_address: Text) -> Text: ... +def fetch_file( + uri: Text, + file: Optional[file] = ..., + username: Optional[Text] = ..., + password: Optional[Text] = ..., +) -> file: ... + +class ShellCommand: + exit_code = ... # type: int + command = ... # type: subprocess._CMD + log_fp = ... # type: six.StringIO + wait = ... # type: bool + fail_fast = ... # type: bool + + def __init__( + self, + command: subprocess._CMD, + wait: bool = ..., + fail_fast: bool = ..., + cwd: Optional[subprocess._TXT] = ..., + ) -> None: .... + + process = ... # type: subprocess.Popen + + def run(self, cwd: Optional[subprocess._CMD] = ...) -> Optional[int]: ... + def setReadOnly(self, value) -> None: ... + def getStatus(self) -> Optional[int]: ... + + status = ... # type: Any + + def getOutput(self) -> Text: ... + + output = ... # type: Any + +class AuthSMTPHandler(logging.handlers.SMTPHandler): + username = ... # type: Text + password = ... # type: Text + def __init__( + self, + mailhost: Text, + username: Text, + password: Text, + fromaddr: Text, + toaddrs: Sequence[Text], + subject: Text, + ) -> None: ... + def emit(self, record: logging.Record) -> None: ... + +class LRUCache(dict): + class _Item: + previous = ... # type: Optional[_Item] + key = ... # type: Hashable + value = ... # type: Any + def __init__(self, key, value) -> None: ... + + capacity = ... # type: int + head = ... # type: Optional[_Item] + tail = ... # type: Optional[_Item] + + def __init__(self, capacity: int) -> None: ... + def __contains__(self, key: Hashable) -> bool: ... + def __iter__(self): ... + def __len__(self) -> int: ... + def __getitem__(self, key: Hashable) -> Any: ... + def __setitem__(self, key: Hashable, value: Any): ... + +class Password: + hashfunc = ... # type: Callable + str = ... # type: Optional[Text] + + def __init__( + self, + str: Optional[Text] = ..., + hashfunc: Optional[Callable] = ..., + ) -> None: ... + def set(self, value: Optional[bytes, Text]): ... + def __eq__(self, other: Any) -> bool: ... + def __len__(self) -> bool: ... + +def notify( + subject: Text, + body: Optional[Text] = ..., + html_body: Optional[Union[Sequence[Text], Text]] = ..., + to_string: Optional[Text] = ..., + attachments: Optional[Iterable] = ..., + append_instance_id: bool = ..., +): ... +def get_utf8_value(value: Text) -> Text: ... +def mklist(value: Any) -> List: ... def pythonize_name(name: Text) -> Text: ... +def write_mime_multipart( + content: List[Tuple[Text, Text]], + compress: bool = ..., + deftype: Text = ..., + delimiter: Text = ..., +): ... +def guess_mime_type(content: Text, deftype: Text) -> Text: ... +def compute_md5( + fp: file, + buf_size: int = ..., + size: Optional[int] = ..., +) -> Tuple[Text, Text, int]: ... +def compute_hash( + fp: file, + buf_size: int = ..., + size: Optional[int] = ..., + hash_algorithm: Any = ..., +) -> Tuple[Text, Text, int]: ... +def find_matching_headers(name: Text, headers: Dict[Text, Text]) -> List[Text]: ... +def merge_headers_by_name(name: Text, headers: Dict[Text, Text]) -> Text: ... + +class RequestHook: + def handle_request_data( + self, + request: boto.connection.HTTPRequest, + response: boto.connection.HTTPResponse, + error: bool = ..., + ): ... + +def host_is_ipv6(hostname: Text) -> bool: ... +def parse_host(hostname: Text) -> Text: ... From a8ff43a12806c435f9ab9133e3b6f58f8e47c6e4 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 5 Sep 2017 21:40:09 +0100 Subject: [PATCH 03/12] fixes --- third_party/2and3/boto/provider.pyi | 112 +---------------- third_party/2and3/boto/utils.pyi | 184 +++++++++++++++------------- 2 files changed, 99 insertions(+), 197 deletions(-) diff --git a/third_party/2and3/boto/provider.pyi b/third_party/2and3/boto/provider.pyi index f90fc5ef9294..cbc008d03e19 100644 --- a/third_party/2and3/boto/provider.pyi +++ b/third_party/2and3/boto/provider.pyi @@ -1,111 +1 @@ -from typing import Any, Optional, Text, Union - -from boto.exceptions import BotoServerError -from boto.gs.acl import CannedACLStrings as CannedGSACLStrings -from boto.pyami.config import Config -from boto.s3.acl import Acl, Policy -from boto.s3.acl import CannedACLStrings as CannedS3ACLStrings - -HEADER_PREFIX_KEY = ... # type: Text -METADATA_PREFIX_KEY = ... # type: Text -AWS_HEADER_PREFIX = ... # type: Text -GOOG_HEADER_PREFIX = ... # type: Text -ACL_HEADER_KEY = ... # type: Text -AUTH_HEADER_KEY = ... # type: Text -COPY_SOURCE_HEADER_KEY = ... # type: Text -COPY_SOURCE_VERSION_ID_HEADER_KEY = ... # type: Text -COPY_SOURCE_RANGE_HEADER_KEY = ... # type: Text -DELETE_MARKER_HEADER_KEY = ... # type: Text -DATE_HEADER_KEY = ... # type: Text -METADATA_DIRECTIVE_HEADER_KEY = ... # type: Text -RESUMABLE_UPLOAD_HEADER_KEY = ... # type: Text -SECURITY_TOKEN_HEADER_KEY = ... # type: Text -STORAGE_CLASS_HEADER_KEY = ... # type: Text -MFA_HEADER_KEY = ... # type: Text -SERVER_SIDE_ENCRYPTION_KEY = ... # type: Text -VERSION_ID_HEADER_KEY = ... # type: Text -RESTORE_HEADER_KEY = ... # type: Text -STORAGE_COPY_ERROR = ... # type: Text -STORAGE_CREATE_ERROR = ... # type: Text -STORAGE_DATA_ERROR = ... # type: Text -STORAGE_PERMISSIONS_ERROR = ... # type: Text -STORAGE_RESPONSE_ERROR = ... # type: Text -NO_CREDENTIALS_PROVIDED = ... # type: object - -class ProfileNotFoundError(ValueError): ... - -class Provider: - CredentialMap = ... # type: Dict[Text, Tuple[Text, Text, Text, Text] - AclClassMap = ... # type: Dict[Text, Union[Policy, Acl]] - CannedAclsMap = ... # type: Dict[Text, Union[CannedS3ACLStrings, CannedGSACLStrings]] - HostKeyMap = ... # type: Dict[Text, Text] - ChunkedTransferSupport = ... # type: Dict[Text, bool] - MetadataServiceSupport = ... # type: Dict[Text, bool] - HeaderInfoMap = ... # type: Dict[Text, Dict[Text, Optional[Text]]] - ErrorMap = ... # type: Dict[Text, BotoServerError] - - host = ... # type: Optional[Text] - port = ... # type: Optional[int] - host_header = ... # type: Optional[Text] - access_key = ... # type: Text - secret_key = ... # type: Text - security_token = ... # type: Optional[Text] - profile_name = ... # type: Optional[Text] - name = ... # type: Text - acl_class = ... # type: Union[Policy, Acl] - canned_acls = ... # type: Union[CannedS3ACLStrings, CannedGSACLStrings] - shared_credentials = ... # type: Any - - def __init__( - self, - name: Text, - access_key: Optional[Text] = ..., - secret_key: Optional[Text] = ..., - security_token: Optional[Text] = ..., - profile_name: Optional[Text] = ..., - ): ... - def get_access_key(self): ... - def set_access_key(self, value: Text): ... - def get_secret_key(self): ... - def set_secret_key(self, value: Text): ... - def get_security_token(self): ... - def set_security_token(self, value: Text): ... - def get_credentials( - self, - access_key: Optional[Text] = ..., - secret_key: Optional[Text] = ..., - security_token: Optional[Text] = ..., - profile_name: Optional[Text] = ..., - ):... - - metadata_prefix = ... # type: Text - header_prefix = ... # type: Text - acl_header = ... # type: Text - auth_header = ... # type: Text - copy_source_header = ... # type: Text - copy_source_version_id = ... # type: Text - copy_source_range_header = ... # type: Optional[Text] - date_header = ... # type: Text - delete_marker = ... # type: Text - metadata_directive_header = ... # type: Text - security_token_header = ... # type: Text - resumable_upload_header = ... # type: Optional[Text] - server_side_encryption_header = ... # type: Optional[Text] - storage_class_header = ... # type: Text - version_id = ... # type: Text - mfa_header = ... # type: Optional[Text] - restore_header = ... # type: Optional[Text] - - def configure_headers(self): ... - - storage_copy_error = ... # type: BotoServerError - storage_create_error = ... # type: BotoServerError - storage_data_error = ... # type: BotoServerError - storage_permissions_error = ... # type: BotoServerError - storage_response_error = ... # type: BotoServerError - - def configure_errors(self): ... - def get_provider_name(self) -> Text: ... - def supports_chunked_transfer(self) -> bool: ... - -def get_default() -> Provider: ... +class Provider: ... diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index e16c08d899c1..ef52a789ac5d 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -1,94 +1,106 @@ +import _thread +import datetime import logging import logging.handlers -import datetime import subprocess -import thread import time -import boto.provider import boto.connection -import six -from typing import Any, List, Hashable, Optional, Text, Union, Tuple - - -JSONDecodeError = ... # type: Exception -qsa_of_interest = ... # type: List[Text] - -def unquote_v(nv: Text) -> Union[Text, Tuple[Text, Text]]: ... +import boto.provider +from typing import ( + Any, + Callable, + Dict, + Hashable, + Iterable, + IO, + List, + Optional, + Sequence, + Tuple, + Type, + Union, +) + + +JSONDecodeError = ... # type: ValueError +qsa_of_interest = ... # type: List[str] + +def unquote_v(nv: str) -> Union[str, Tuple[str, str]]: ... def canonical_string( - method: Text, - path: Text, - headers: Dict[Text, Text], + method: str, + path: str, + headers: Dict[str, str], expires: Optional[int] = ..., provider: Optional[boto.provider.Provider] = ..., ): ... def merge_meta( - headers: Dict[Text, Text], - metadata: Dict[Text, Text], + headers: Dict[str, str], + metadata: Dict[str, str], provider: Optional[boto.provider.Provider] = ..., ): ... -def get_aws_metadata(headers: Dict[Text, Text], provider: Optional[boto.provider.Provider] = ...): ... +def get_aws_metadata(headers: Dict[str, str], provider: Optional[boto.provider.Provider] = ...): ... def retry_url( - url: Text, + url: str, retry_on_404: bool = ..., num_retries: int = ..., timeout: Optional[int] = ..., ): ... -class LazyLoadMetadata(dict): +class LazyLoadMetadata(Dict): def __init__( self, - url: Text, + url: str, num_retries: int, timeout: Optional[int] = ..., ) -> None: ... def __getitem__(self, key: Hashable): ... def get(self, key: Hashable, default: Optional[Any] = ...) -> Any: ... - def values(self) -> List[Any]: ... - def items(self) -> List[Tuple[Any, Any]]: ... + def values(self): ... + def items(self): ... def get_instance_metadata( - version: Text = ..., - url: Text = ..., - data: Text = ..., + version: str = ..., + url: str = ..., + data: str = ..., timeout: Optional[int] = ..., num_retries: int = ... ) -> Optional[LazyLoadMetadata]: ... def get_instance_identity( - version: Text = ..., - url: Text = ..., + version: str = ..., + url: str = ..., timeout: Optional[int] = ..., num_retries: int = ..., -) -> Optional[Dict[Text, Any]]: ... +) -> Optional[Dict[str, Any]]: ... def get_instance_userdata( - version: Text = ..., - sep: Optional[Text] = ..., - url: Text = ..., + version: str = ..., + sep: Optional[str] = ..., + url: str = ..., timeout: Optional[int] = ..., num_retries: int = ..., -) -> Dict[Text, Text]: ... - -ISO8601 = ... # type: Text -ISO8601_MS = ... # type: Text -RFC1123 = ... # type: Text -LOCALE_LOCK = ... # type: therad.LockType - -def setlocale(name: Union[Text, Tuple[Text, Text]]): ... -def get_ts(ts: Optional[time.struct_time] = ...) -> Text: ... -def parse_ts(ts: Text) -> datetime.datetime: ... -def find_class(module_name: Text, class_name: Optional[Text] = ...) -> Optional[Any]: ... -def update_dme(username: Text, password: Text, dme_id: Text, ip_address: Text) -> Text: ... +) -> Dict[str, str]: ... + +ISO8601 = ... # type: str +ISO8601_MS = ... # type: str +RFC1123 = ... # type: str +LOCALE_LOCK = ... # type: _thread.LockType + +def setlocale(name: Union[str, Tuple[str, str]]): ... +def get_ts(ts: Optional[time.struct_time] = ...) -> str: ... +def parse_ts(ts: str) -> datetime.datetime: ... +def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[object]]: ... +def update_dme(username: str, password: str, dme_id: str, ip_address: str) -> str: ... def fetch_file( - uri: Text, - file: Optional[file] = ..., - username: Optional[Text] = ..., - password: Optional[Text] = ..., -) -> file: ... + uri: str, + file: Optional[IO] = ..., + username: Optional[str] = ..., + password: Optional[str] = ..., +) -> IO: ... class ShellCommand: exit_code = ... # type: int command = ... # type: subprocess._CMD - log_fp = ... # type: six.StringIO + log_fp = ... # type: IO wait = ... # type: bool fail_fast = ... # type: bool @@ -98,7 +110,7 @@ class ShellCommand: wait: bool = ..., fail_fast: bool = ..., cwd: Optional[subprocess._TXT] = ..., - ) -> None: .... + ) -> None: ... process = ... # type: subprocess.Popen @@ -106,29 +118,29 @@ class ShellCommand: def setReadOnly(self, value) -> None: ... def getStatus(self) -> Optional[int]: ... - status = ... # type: Any + status = ... # type: Optional[int] - def getOutput(self) -> Text: ... + def getOutput(self) -> str: ... - output = ... # type: Any + output = ... # type: str class AuthSMTPHandler(logging.handlers.SMTPHandler): - username = ... # type: Text - password = ... # type: Text + username = ... # type: str + password = ... # type: str def __init__( self, - mailhost: Text, - username: Text, - password: Text, - fromaddr: Text, - toaddrs: Sequence[Text], - subject: Text, + mailhost: str, + username: str, + password: str, + fromaddr: str, + toaddrs: Sequence[str], + subject: str, ) -> None: ... - def emit(self, record: logging.Record) -> None: ... + def emit(self, record: logging.LogRecord) -> None: ... -class LRUCache(dict): +class LRUCache(Dict): class _Item: - previous = ... # type: Optional[_Item] + previous = ... # type: Optional[Any] key = ... # type: Hashable value = ... # type: Any def __init__(self, key, value) -> None: ... @@ -138,7 +150,7 @@ class LRUCache(dict): tail = ... # type: Optional[_Item] def __init__(self, capacity: int) -> None: ... - def __contains__(self, key: Hashable) -> bool: ... + def __contains__(self, key) -> bool: ... def __iter__(self): ... def __len__(self) -> int: ... def __getitem__(self, key: Hashable) -> Any: ... @@ -146,48 +158,48 @@ class LRUCache(dict): class Password: hashfunc = ... # type: Callable - str = ... # type: Optional[Text] + str = ... # type: Optional[str] def __init__( self, - str: Optional[Text] = ..., + str: Optional[str] = ..., hashfunc: Optional[Callable] = ..., ) -> None: ... - def set(self, value: Optional[bytes, Text]): ... + def set(self, value: Union[bytes, str]): ... def __eq__(self, other: Any) -> bool: ... def __len__(self) -> bool: ... def notify( - subject: Text, - body: Optional[Text] = ..., - html_body: Optional[Union[Sequence[Text], Text]] = ..., - to_string: Optional[Text] = ..., + subject: str, + body: Optional[str] = ..., + html_body: Optional[Union[Sequence[str], str]] = ..., + to_string: Optional[str] = ..., attachments: Optional[Iterable] = ..., append_instance_id: bool = ..., ): ... -def get_utf8_value(value: Text) -> Text: ... +def get_utf8_value(value: str) -> str: ... def mklist(value: Any) -> List: ... -def pythonize_name(name: Text) -> Text: ... +def pythonize_name(name: str) -> str: ... def write_mime_multipart( - content: List[Tuple[Text, Text]], + content: List[Tuple[str, str]], compress: bool = ..., - deftype: Text = ..., - delimiter: Text = ..., + deftype: str = ..., + delimiter: str = ..., ): ... -def guess_mime_type(content: Text, deftype: Text) -> Text: ... +def guess_mime_type(content: str, deftype: str) -> str: ... def compute_md5( - fp: file, + fp: IO, buf_size: int = ..., size: Optional[int] = ..., -) -> Tuple[Text, Text, int]: ... +) -> Tuple[str, str, int]: ... def compute_hash( - fp: file, + fp: IO, buf_size: int = ..., size: Optional[int] = ..., hash_algorithm: Any = ..., -) -> Tuple[Text, Text, int]: ... -def find_matching_headers(name: Text, headers: Dict[Text, Text]) -> List[Text]: ... -def merge_headers_by_name(name: Text, headers: Dict[Text, Text]) -> Text: ... +) -> Tuple[str, str, int]: ... +def find_matching_headers(name: str, headers: Dict[str, str]) -> List[str]: ... +def merge_headers_by_name(name: str, headers: Dict[str, str]) -> str: ... class RequestHook: def handle_request_data( @@ -197,5 +209,5 @@ class RequestHook: error: bool = ..., ): ... -def host_is_ipv6(hostname: Text) -> bool: ... -def parse_host(hostname: Text) -> Text: ... +def host_is_ipv6(hostname: str) -> bool: ... +def parse_host(hostname: str) -> str: ... From f1380620e7153547d62764073338a8b899fccab6 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Mon, 11 Sep 2017 18:41:41 -0700 Subject: [PATCH 04/12] Fix types --- third_party/2and3/boto/provider.pyi | 1 - third_party/2and3/boto/utils.pyi | 60 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 third_party/2and3/boto/provider.pyi diff --git a/third_party/2and3/boto/provider.pyi b/third_party/2and3/boto/provider.pyi deleted file mode 100644 index cbc008d03e19..000000000000 --- a/third_party/2and3/boto/provider.pyi +++ /dev/null @@ -1 +0,0 @@ -class Provider: ... diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index ef52a789ac5d..b0f86f1c391c 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -1,4 +1,3 @@ -import _thread import datetime import logging import logging.handlers @@ -6,14 +5,14 @@ import subprocess import time import boto.connection -import boto.provider from typing import ( + _KT, + _VT, Any, Callable, Dict, - Hashable, - Iterable, IO, + Iterable, List, Optional, Sequence, @@ -22,24 +21,27 @@ from typing import ( Union, ) +_Provider = Any # TODO replace this with boto.provider.Provider once stubs exist +_LockType = Any # TODO replace this with _thread.LockType once stubs exist -JSONDecodeError = ... # type: ValueError +JSONDecodeError = ... # type: Type[ValueError] qsa_of_interest = ... # type: List[str] + def unquote_v(nv: str) -> Union[str, Tuple[str, str]]: ... def canonical_string( method: str, path: str, headers: Dict[str, str], expires: Optional[int] = ..., - provider: Optional[boto.provider.Provider] = ..., + provider: Optional[_Provider] = ..., ): ... def merge_meta( headers: Dict[str, str], metadata: Dict[str, str], - provider: Optional[boto.provider.Provider] = ..., + provider: Optional[_Provider] = ..., ): ... -def get_aws_metadata(headers: Dict[str, str], provider: Optional[boto.provider.Provider] = ...): ... +def get_aws_metadata(headers: Dict[str, str], provider: Optional[_Provider] = ...): ... def retry_url( url: str, retry_on_404: bool = ..., @@ -47,24 +49,21 @@ def retry_url( timeout: Optional[int] = ..., ): ... -class LazyLoadMetadata(Dict): +class LazyLoadMetadata(Dict[_KT, _VT]): def __init__( self, url: str, num_retries: int, timeout: Optional[int] = ..., ) -> None: ... - def __getitem__(self, key: Hashable): ... - def get(self, key: Hashable, default: Optional[Any] = ...) -> Any: ... - def values(self): ... - def items(self): ... + def get(self, key: _KT, default: Optional[Any] = ...) -> Any: ... def get_instance_metadata( version: str = ..., url: str = ..., data: str = ..., timeout: Optional[int] = ..., - num_retries: int = ... + num_retries: int = ..., ) -> Optional[LazyLoadMetadata]: ... def get_instance_identity( version: str = ..., @@ -83,12 +82,12 @@ def get_instance_userdata( ISO8601 = ... # type: str ISO8601_MS = ... # type: str RFC1123 = ... # type: str -LOCALE_LOCK = ... # type: _thread.LockType +LOCALE_LOCK = ... # type: _LockType def setlocale(name: Union[str, Tuple[str, str]]): ... def get_ts(ts: Optional[time.struct_time] = ...) -> str: ... def parse_ts(ts: str) -> datetime.datetime: ... -def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[object]]: ... +def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[Any]]: ... def update_dme(username: str, password: str, dme_id: str, ip_address: str) -> str: ... def fetch_file( uri: str, @@ -138,34 +137,33 @@ class AuthSMTPHandler(logging.handlers.SMTPHandler): ) -> None: ... def emit(self, record: logging.LogRecord) -> None: ... -class LRUCache(Dict): +class LRUCache(Dict[_KT, _VT]): class _Item: - previous = ... # type: Optional[Any] - key = ... # type: Hashable - value = ... # type: Any - def __init__(self, key, value) -> None: ... + previous = ... # type: Optional[LRUCache._Item] + key = ... # type: _KT + value = ... # type: _VT + def __init__(self, key: _KT, value: _VT) -> None: ... capacity = ... # type: int - head = ... # type: Optional[_Item] - tail = ... # type: Optional[_Item] + head = ... # type: Optional[LRUCache._Item] + tail = ... # type: Optional[LRUCache._Item] def __init__(self, capacity: int) -> None: ... - def __contains__(self, key) -> bool: ... - def __iter__(self): ... - def __len__(self) -> int: ... - def __getitem__(self, key: Hashable) -> Any: ... - def __setitem__(self, key: Hashable, value: Any): ... + + +# This exists to work around Password.str's name shadowing the str type +_str = str class Password: hashfunc = ... # type: Callable - str = ... # type: Optional[str] + str = ... # type: Optional[_str] def __init__( self, - str: Optional[str] = ..., + str: Optional[_str] = ..., hashfunc: Optional[Callable] = ..., ) -> None: ... - def set(self, value: Union[bytes, str]): ... + def set(self, value: Union[bytes, _str]): ... def __eq__(self, other: Any) -> bool: ... def __len__(self) -> bool: ... From 6c28d5c5131da5e31bb67e9c193cc0061011a766 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 12 Sep 2017 04:52:14 -0700 Subject: [PATCH 05/12] Remove types --- third_party/2and3/boto/utils.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index b0f86f1c391c..1b03d1038374 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -140,9 +140,9 @@ class AuthSMTPHandler(logging.handlers.SMTPHandler): class LRUCache(Dict[_KT, _VT]): class _Item: previous = ... # type: Optional[LRUCache._Item] - key = ... # type: _KT - value = ... # type: _VT - def __init__(self, key: _KT, value: _VT) -> None: ... + key = ... + value = ... + def __init__(self, key, value) -> None: ... capacity = ... # type: int head = ... # type: Optional[LRUCache._Item] From 3561d29430179cb96c876c9240fb2c4b63b8d9a4 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 12 Sep 2017 05:21:27 -0700 Subject: [PATCH 06/12] More return values --- third_party/2and3/boto/utils.pyi | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 1b03d1038374..aecb8c2e7cc6 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -35,19 +35,22 @@ def canonical_string( headers: Dict[str, str], expires: Optional[int] = ..., provider: Optional[_Provider] = ..., -): ... +) -> str: ... def merge_meta( headers: Dict[str, str], metadata: Dict[str, str], provider: Optional[_Provider] = ..., -): ... -def get_aws_metadata(headers: Dict[str, str], provider: Optional[_Provider] = ...): ... +) -> Dict[str, str]: ... +def get_aws_metadata( + headers: Dict[str, str], + provider: Optional[_Provider] = ..., +) -> Dict[str, str]: ... def retry_url( url: str, retry_on_404: bool = ..., num_retries: int = ..., timeout: Optional[int] = ..., -): ... +) -> str: ... class LazyLoadMetadata(Dict[_KT, _VT]): def __init__( @@ -84,7 +87,7 @@ ISO8601_MS = ... # type: str RFC1123 = ... # type: str LOCALE_LOCK = ... # type: _LockType -def setlocale(name: Union[str, Tuple[str, str]]): ... +def setlocale(name: Union[str, Tuple[str, str]]) -> None: ... def get_ts(ts: Optional[time.struct_time] = ...) -> str: ... def parse_ts(ts: str) -> datetime.datetime: ... def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[Any]]: ... @@ -163,7 +166,7 @@ class Password: str: Optional[_str] = ..., hashfunc: Optional[Callable] = ..., ) -> None: ... - def set(self, value: Union[bytes, _str]): ... + def set(self, value: Union[bytes, _str]) -> None: ... def __eq__(self, other: Any) -> bool: ... def __len__(self) -> bool: ... @@ -174,7 +177,7 @@ def notify( to_string: Optional[str] = ..., attachments: Optional[Iterable] = ..., append_instance_id: bool = ..., -): ... +) -> None: ... def get_utf8_value(value: str) -> str: ... def mklist(value: Any) -> List: ... def pythonize_name(name: str) -> str: ... @@ -183,7 +186,7 @@ def write_mime_multipart( compress: bool = ..., deftype: str = ..., delimiter: str = ..., -): ... +) -> str: ... def guess_mime_type(content: str, deftype: str) -> str: ... def compute_md5( fp: IO, @@ -205,7 +208,7 @@ class RequestHook: request: boto.connection.HTTPRequest, response: boto.connection.HTTPResponse, error: bool = ..., - ): ... + ) -> Any: ... def host_is_ipv6(hostname: str) -> bool: ... def parse_host(hostname: str) -> str: ... From 0fcbf5c2582ea084402f0cce77aee3497a45af11 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 12 Sep 2017 05:52:48 -0700 Subject: [PATCH 07/12] Add __str__ and fix __len__ return type --- third_party/2and3/boto/utils.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index aecb8c2e7cc6..c840abcfa6a3 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -167,8 +167,9 @@ class Password: hashfunc: Optional[Callable] = ..., ) -> None: ... def set(self, value: Union[bytes, _str]) -> None: ... + def __str__(self) -> _str: ... def __eq__(self, other: Any) -> bool: ... - def __len__(self) -> bool: ... + def __len__(self) -> int: ... def notify( subject: str, From 908e8399dce7ee47a85ce9fa231fb53aeee22fe6 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 26 Sep 2017 18:50:39 -0700 Subject: [PATCH 08/12] Update types --- third_party/2and3/boto/utils.pyi | 74 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index c840abcfa6a3..b24eb302067a 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -1,29 +1,48 @@ import datetime -import logging import logging.handlers import subprocess +import sys import time import boto.connection +from email.message import Message from typing import ( - _KT, - _VT, Any, Callable, Dict, IO, Iterable, List, + Mapping, Optional, Sequence, Tuple, Type, + TypeVar, Union, ) +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +# TODO move _StringIO definition into boto.compat once stubs exist +if sys.version_info[0] >= 3: + import io + _StringIO = io.StringIO + + from hashlib import _Hash + _HashType = _Hash +else: + import StringIO + _StringIO = StringIO.StringIO + + from hashlib import _hash + _HashType = _hash + _Provider = Any # TODO replace this with boto.provider.Provider once stubs exist _LockType = Any # TODO replace this with _thread.LockType once stubs exist + JSONDecodeError = ... # type: Type[ValueError] qsa_of_interest = ... # type: List[str] @@ -32,19 +51,19 @@ def unquote_v(nv: str) -> Union[str, Tuple[str, str]]: ... def canonical_string( method: str, path: str, - headers: Dict[str, str], + headers: Mapping[str, Optional[str]], expires: Optional[int] = ..., provider: Optional[_Provider] = ..., ) -> str: ... def merge_meta( - headers: Dict[str, str], - metadata: Dict[str, str], + headers: Mapping[str, str], + metadata: Mapping[str, str], provider: Optional[_Provider] = ..., -) -> Dict[str, str]: ... +) -> Mapping[str, str]: ... def get_aws_metadata( - headers: Dict[str, str], + headers: Mapping[str, str], provider: Optional[_Provider] = ..., -) -> Dict[str, str]: ... +) -> Mapping[str, str]: ... def retry_url( url: str, retry_on_404: bool = ..., @@ -59,7 +78,6 @@ class LazyLoadMetadata(Dict[_KT, _VT]): num_retries: int, timeout: Optional[int] = ..., ) -> None: ... - def get(self, key: _KT, default: Optional[Any] = ...) -> Any: ... def get_instance_metadata( version: str = ..., @@ -73,14 +91,14 @@ def get_instance_identity( url: str = ..., timeout: Optional[int] = ..., num_retries: int = ..., -) -> Optional[Dict[str, Any]]: ... +) -> Optional[Mapping[str, Any]]: ... def get_instance_userdata( version: str = ..., sep: Optional[str] = ..., url: str = ..., timeout: Optional[int] = ..., num_retries: int = ..., -) -> Dict[str, str]: ... +) -> Mapping[str, str]: ... ISO8601 = ... # type: str ISO8601_MS = ... # type: str @@ -94,15 +112,15 @@ def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Ty def update_dme(username: str, password: str, dme_id: str, ip_address: str) -> str: ... def fetch_file( uri: str, - file: Optional[IO] = ..., + file: Optional[IO[str]] = ..., username: Optional[str] = ..., password: Optional[str] = ..., -) -> IO: ... +) -> Optional[IO[str]]: ... class ShellCommand: exit_code = ... # type: int command = ... # type: subprocess._CMD - log_fp = ... # type: IO + log_fp = ... # type: _StringIO wait = ... # type: bool fail_fast = ... # type: bool @@ -138,15 +156,16 @@ class AuthSMTPHandler(logging.handlers.SMTPHandler): toaddrs: Sequence[str], subject: str, ) -> None: ... - def emit(self, record: logging.LogRecord) -> None: ... class LRUCache(Dict[_KT, _VT]): class _Item: previous = ... # type: Optional[LRUCache._Item] - key = ... - value = ... - def __init__(self, key, value) -> None: ... + next = ... # type: Optional[LRUCache._Item] + key = ... # type: _KT + value = ... # type: _VT + def __init__(self, key: _KT, value: _VT) -> None: ... + _dict = Dict[_KT, 'LRUCache._Item'] capacity = ... # type: int head = ... # type: Optional[LRUCache._Item] tail = ... # type: Optional[LRUCache._Item] @@ -158,16 +177,15 @@ class LRUCache(Dict[_KT, _VT]): _str = str class Password: - hashfunc = ... # type: Callable + hashfunc = ... # type: Callable[[bytes], _HashType] str = ... # type: Optional[_str] def __init__( self, str: Optional[_str] = ..., - hashfunc: Optional[Callable] = ..., + hashfunc: Optional[Callable[bytes], _HashType] = ..., ) -> None: ... def set(self, value: Union[bytes, _str]) -> None: ... - def __str__(self) -> _str: ... def __eq__(self, other: Any) -> bool: ... def __len__(self) -> int: ... @@ -176,10 +194,10 @@ def notify( body: Optional[str] = ..., html_body: Optional[Union[Sequence[str], str]] = ..., to_string: Optional[str] = ..., - attachments: Optional[Iterable] = ..., + attachments: Optional[Iterable[Message]] = ..., append_instance_id: bool = ..., ) -> None: ... -def get_utf8_value(value: str) -> str: ... +def get_utf8_value(value: str) -> bytes: ... def mklist(value: Any) -> List: ... def pythonize_name(name: str) -> str: ... def write_mime_multipart( @@ -190,18 +208,18 @@ def write_mime_multipart( ) -> str: ... def guess_mime_type(content: str, deftype: str) -> str: ... def compute_md5( - fp: IO, + fp: IO[Any], buf_size: int = ..., size: Optional[int] = ..., ) -> Tuple[str, str, int]: ... def compute_hash( - fp: IO, + fp: IO[Any], buf_size: int = ..., size: Optional[int] = ..., hash_algorithm: Any = ..., ) -> Tuple[str, str, int]: ... -def find_matching_headers(name: str, headers: Dict[str, str]) -> List[str]: ... -def merge_headers_by_name(name: str, headers: Dict[str, str]) -> str: ... +def find_matching_headers(name: str, headers: Mapping[str, Optional[str]]) -> List[str]: ... +def merge_headers_by_name(name: str, headers: Mapping[str, Optional[str]]) -> str: ... class RequestHook: def handle_request_data( From 00105a07e8ff8f9df495d994078ead58f3a48a19 Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 26 Sep 2017 18:53:10 -0700 Subject: [PATCH 09/12] Update --- third_party/2and3/boto/utils.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index b24eb302067a..9755e91928b0 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -9,6 +9,7 @@ from email.message import Message from typing import ( Any, Callable, + ContextManager, Dict, IO, Iterable, @@ -105,7 +106,7 @@ ISO8601_MS = ... # type: str RFC1123 = ... # type: str LOCALE_LOCK = ... # type: _LockType -def setlocale(name: Union[str, Tuple[str, str]]) -> None: ... +def setlocale(name: Union[str, Tuple[str, str]]) -> ContextManager[str]: ... def get_ts(ts: Optional[time.struct_time] = ...) -> str: ... def parse_ts(ts: str) -> datetime.datetime: ... def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[Any]]: ... From 0baa5c1c8fc0b42d136c05fae11de3c32924bbaa Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Tue, 26 Sep 2017 19:17:15 -0700 Subject: [PATCH 10/12] Update --- third_party/2and3/boto/utils.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 9755e91928b0..b79b3932b24a 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -163,10 +163,10 @@ class LRUCache(Dict[_KT, _VT]): previous = ... # type: Optional[LRUCache._Item] next = ... # type: Optional[LRUCache._Item] key = ... # type: _KT - value = ... # type: _VT + value = ... # type: _VT def __init__(self, key: _KT, value: _VT) -> None: ... - _dict = Dict[_KT, 'LRUCache._Item'] + _dict = ... #type: Dict[_KT, LRUCache._Item] capacity = ... # type: int head = ... # type: Optional[LRUCache._Item] tail = ... # type: Optional[LRUCache._Item] @@ -184,7 +184,7 @@ class Password: def __init__( self, str: Optional[_str] = ..., - hashfunc: Optional[Callable[bytes], _HashType] = ..., + hashfunc: Optional[Callable[[bytes], _HashType]] = ..., ) -> None: ... def set(self, value: Union[bytes, _str]) -> None: ... def __eq__(self, other: Any) -> bool: ... From 8ba62da89a178060eb14ca64841e7e9301fffc7f Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Wed, 27 Sep 2017 10:44:24 -0700 Subject: [PATCH 11/12] Fix flake8 and remove _KT/_VT --- third_party/2and3/boto/utils.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index b79b3932b24a..4f6321a8b0ad 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -162,11 +162,11 @@ class LRUCache(Dict[_KT, _VT]): class _Item: previous = ... # type: Optional[LRUCache._Item] next = ... # type: Optional[LRUCache._Item] - key = ... # type: _KT - value = ... # type: _VT - def __init__(self, key: _KT, value: _VT) -> None: ... + key = ... + value = ... + def __init__(self, key, value) -> None: ... - _dict = ... #type: Dict[_KT, LRUCache._Item] + _dict = ... # type: Dict[_KT, LRUCache._Item] capacity = ... # type: int head = ... # type: Optional[LRUCache._Item] tail = ... # type: Optional[LRUCache._Item] From 6c480d8438d3c1035c78fc136361e3ea142fe25d Mon Sep 17 00:00:00 2001 From: Max Rozentsveyg Date: Wed, 27 Sep 2017 10:56:27 -0700 Subject: [PATCH 12/12] Fix --- third_party/2and3/boto/utils.pyi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index 4f6321a8b0ad..b3c542540d9f 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -5,7 +5,6 @@ import sys import time import boto.connection -from email.message import Message from typing import ( Any, Callable, @@ -26,20 +25,26 @@ from typing import ( _KT = TypeVar('_KT') _VT = TypeVar('_VT') -# TODO move _StringIO definition into boto.compat once stubs exist if sys.version_info[0] >= 3: + # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import io _StringIO = io.StringIO from hashlib import _Hash _HashType = _Hash + + from email.message import Message as _Message else: + # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import StringIO _StringIO = StringIO.StringIO from hashlib import _hash _HashType = _hash + # TODO use email.message.Message once stubs exist + _Message = Any + _Provider = Any # TODO replace this with boto.provider.Provider once stubs exist _LockType = Any # TODO replace this with _thread.LockType once stubs exist @@ -166,7 +171,7 @@ class LRUCache(Dict[_KT, _VT]): value = ... def __init__(self, key, value) -> None: ... - _dict = ... # type: Dict[_KT, LRUCache._Item] + _dict = ... # type: Dict[_KT, LRUCache._Item] capacity = ... # type: int head = ... # type: Optional[LRUCache._Item] tail = ... # type: Optional[LRUCache._Item] @@ -195,7 +200,7 @@ def notify( body: Optional[str] = ..., html_body: Optional[Union[Sequence[str], str]] = ..., to_string: Optional[str] = ..., - attachments: Optional[Iterable[Message]] = ..., + attachments: Optional[Iterable[_Message]] = ..., append_instance_id: bool = ..., ) -> None: ... def get_utf8_value(value: str) -> bytes: ...