From 0655e21853be84faf30cffd8642eef493247741b Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 7 Oct 2019 18:06:42 +0300 Subject: [PATCH 1/9] Added revised stubs for geoip2 third party library --- third_party/2and3/geoip2/__init__.pyi | 0 third_party/2and3/geoip2/database.pyi | 24 ++++++++ third_party/2and3/geoip2/errors.pyi | 20 ++++++ third_party/2and3/geoip2/mixins.pyi | 8 +++ third_party/2and3/geoip2/models.pyi | 68 +++++++++++++++++++++ third_party/2and3/geoip2/records.pyi | 87 +++++++++++++++++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 third_party/2and3/geoip2/__init__.pyi create mode 100644 third_party/2and3/geoip2/database.pyi create mode 100644 third_party/2and3/geoip2/errors.pyi create mode 100644 third_party/2and3/geoip2/mixins.pyi create mode 100644 third_party/2and3/geoip2/models.pyi create mode 100644 third_party/2and3/geoip2/records.pyi diff --git a/third_party/2and3/geoip2/__init__.pyi b/third_party/2and3/geoip2/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/third_party/2and3/geoip2/database.pyi b/third_party/2and3/geoip2/database.pyi new file mode 100644 index 000000000000..f55d4b61aa1d --- /dev/null +++ b/third_party/2and3/geoip2/database.pyi @@ -0,0 +1,24 @@ +# Stubs for geoip2.database (Python 2 and 3) + +from types import TracebackType +from typing import Optional, Sequence, Text, Type + +from maxminddb.reader import Metadata +from geoip2.models import AnonymousIP, ASN, City, ConnectionType, Country, Domain, Enterprise, ISP + +_Locales = Optional[Sequence[Text]] + +class Reader: + def __init__(self, filename: Text, locales: _Locales = ..., mode: int = ...) -> None: ... + def __enter__(self) -> Reader: ... + def __exit__(self, exc_type: Optional[Type[BaseException]] = None, exc_val: Optional[BaseException] = None, exc_tb: Optional[TracebackType] = None) -> None: ... + def country(self, ip_address: Text) -> Country: ... + def city(self, ip_address: Text) -> City: ... + def anonymous_ip(self, ip_address: Text) -> AnonymousIP: ... + def asn(self, ip_address: Text) -> ASN: ... + def connection_type(self, ip_address: Text) -> ConnectionType: ... + def domain(self, ip_address: Text) -> Domain: ... + def enterprise(self, ip_address: Text) -> Enterprise: ... + def isp(self, ip_address: Text) -> ISP: ... + def metadata(self) -> Metadata: ... + def close(self) -> None: ... diff --git a/third_party/2and3/geoip2/errors.pyi b/third_party/2and3/geoip2/errors.pyi new file mode 100644 index 000000000000..c12f60a054f4 --- /dev/null +++ b/third_party/2and3/geoip2/errors.pyi @@ -0,0 +1,20 @@ +# Stubs for geoip2.errors (Python 2 and 3) + +from typing import Optional, Text + +class GeoIP2Error(RuntimeError): ... + +class AddressNotFoundError(GeoIP2Error): ... + +class AuthenticationError(GeoIP2Error): ... + +class HTTPError(GeoIP2Error): + http_status: Optional[int] + uri: Optional[Text] + def __init__(self, message: Text, http_status: Optional[int] = ..., uri: Optional[Text] = ...) -> None: ... + +class InvalidRequestError(GeoIP2Error): ... + +class OutOfQueriesError(GeoIP2Error): ... + +class PermissionRequiredError(GeoIP2Error): ... diff --git a/third_party/2and3/geoip2/mixins.pyi b/third_party/2and3/geoip2/mixins.pyi new file mode 100644 index 000000000000..a3ca62986c16 --- /dev/null +++ b/third_party/2and3/geoip2/mixins.pyi @@ -0,0 +1,8 @@ +# Stubs for geoip2.mixins (Python 2 and 3) + +from typing import Any + +class SimpleEquality: + __metaclass__: Any + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... diff --git a/third_party/2and3/geoip2/models.pyi b/third_party/2and3/geoip2/models.pyi new file mode 100644 index 000000000000..c6c832302ad6 --- /dev/null +++ b/third_party/2and3/geoip2/models.pyi @@ -0,0 +1,68 @@ +# Stubs for geoip2.models (Python 2 and 3) + +from typing import Any, Mapping, Optional, Sequence, Text + +from geoip2 import records + +from geoip2.mixins import SimpleEquality + +_Locales = Optional[Sequence[Text]] +_RawResponse = Mapping[Text, Mapping[Text, Any]] + +class Country(SimpleEquality): + continent: records.Continent + country: records.Country + registered_country: records.Country + represented_country: records.RepresentedCountry + maxmind: records.MaxMind + traits: records.Traits + raw: _RawResponse + def __init__(self, raw_response: _RawResponse, locales: _Locales = ...) -> None: ... + +class City(Country): + city: records.City + location: records.Location + postal: records.Postal + subdivisions: records.Subdivisions + def __init__(self, raw_response: _RawResponse, locales: _Locales = ...) -> None: ... + +class Insights(City): ... + +class Enterprise(City): ... + +class SimpleModel(SimpleEquality): + __metaclass__: Any + +class AnonymousIP(SimpleModel): + is_anonymous: bool + is_anonymous_vpn: bool + is_hosting_provider: bool + is_public_proxy: bool + is_tor_exit_node: bool + ip_address: Optional[Text] + raw: _RawResponse + def __init__(self, raw: _RawResponse) -> None: ... + +class ASN(SimpleModel): + autonomous_system_number: Optional[int] + autonomous_system_organization: Optional[Text] + ip_address: Optional[Text] + raw: _RawResponse + def __init__(self, raw: _RawResponse) -> None: ... + +class ConnectionType(SimpleModel): + connection_type: Optional[Text] + ip_address: Optional[Text] + raw: _RawResponse + def __init__(self, raw: _RawResponse) -> None: ... + +class Domain(SimpleModel): + domain: Optional[Text] + ip_address: Optional[Text] + raw: Optional[Text] + def __init__(self, raw: _RawResponse) -> None: ... + +class ISP(ASN): + isp: Optional[Text] + organization: Optional[Text] + def __init__(self, raw: _RawResponse) -> None: ... diff --git a/third_party/2and3/geoip2/records.pyi b/third_party/2and3/geoip2/records.pyi new file mode 100644 index 000000000000..aaeec8c6a38b --- /dev/null +++ b/third_party/2and3/geoip2/records.pyi @@ -0,0 +1,87 @@ +# Stubs for geoip2.records (Python 2 and 3) + +from typing import Any, Mapping, Optional, Sequence, Text, Tuple + +from geoip2.mixins import SimpleEquality + +_Locales = Optional[Sequence[Text]] +_Names = Mapping[Text, Text] + +class Record(SimpleEquality): + __metaclass__: Any + def __init__(self, **kwargs: Any) -> None: ... + def __setattr__(self, name: Text, value: Any) -> None: ... + +class PlaceRecord(Record): + __metaclass__: Any + def __init__(self, locales: _Locales = ..., **kwargs: Any) -> None: ... + @property + def name(self) -> Text: ... + +class City(PlaceRecord): + confidence: int + geoname_id: int + names: _Names + +class Continent(PlaceRecord): + code: Text + geoname_id: int + names: _Names + +class Country(PlaceRecord): + confidence: int + geoname_id: int + is_in_european_union: bool + iso_code: Text + names: _Names + def __init__(self, locales: _Locales = ..., **kwargs: Any) -> None: ... + +class RepresentedCountry(Country): + type: Text + +class Location(Record): + average_income: int + accuracy_radius: int + latitude: float + longitude: float + metro_code: int + population_density: int + time_zone: Text + +class MaxMind(Record): + queries_remaining: int + +class Postal(Record): + code: Text + confidence: int + +class Subdivision(PlaceRecord): + confidence: int + geoname_id: int + iso_code: Text + names: _Names + +class Subdivisions(Tuple[Subdivision]): + def __new__(cls, locales: _Locales, *subdivisions: Subdivision) -> Subdivisions: ... + def __init__(self, locales: _Locales, *subdivisions: Subdivision) -> None: ... + @property + def most_specific(self) -> Subdivision: ... + +class Traits(Record): + autonomous_system_number: int + autonomous_system_organization: Text + connection_type: Text + domain: Text + ip_address: Text + is_anonymous: bool + is_anonymous_proxy: bool + is_anonymous_vpn: bool + is_hosting_provider: bool + is_legitimate_proxy: bool + is_public_proxy: bool + is_satellite_provider: bool + is_tor_exit_node: bool + isp: Text + organization: Text + user_type: Text + def __init__(self, **kwargs: Any) -> None: ... From 7121a1217b39dfcef9e8a288b00d0882cecf4770 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 7 Oct 2019 18:15:05 +0300 Subject: [PATCH 2/9] Fixed according to flake8 --- third_party/2and3/geoip2/database.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/geoip2/database.pyi b/third_party/2and3/geoip2/database.pyi index f55d4b61aa1d..e55adf4cba27 100644 --- a/third_party/2and3/geoip2/database.pyi +++ b/third_party/2and3/geoip2/database.pyi @@ -11,7 +11,7 @@ _Locales = Optional[Sequence[Text]] class Reader: def __init__(self, filename: Text, locales: _Locales = ..., mode: int = ...) -> None: ... def __enter__(self) -> Reader: ... - def __exit__(self, exc_type: Optional[Type[BaseException]] = None, exc_val: Optional[BaseException] = None, exc_tb: Optional[TracebackType] = None) -> None: ... + def __exit__(self, exc_type: Optional[Type[BaseException]] = ..., exc_val: Optional[BaseException] = ..., exc_tb: Optional[TracebackType] = ...) -> None: ... def country(self, ip_address: Text) -> Country: ... def city(self, ip_address: Text) -> City: ... def anonymous_ip(self, ip_address: Text) -> AnonymousIP: ... From 952177794c99698f575cacf28afec450e39b4572 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 7 Oct 2019 18:18:58 +0300 Subject: [PATCH 3/9] Moving to Python 3 only, as there're compatibility problems with Python 2. --- third_party/{2and3 => 3}/geoip2/__init__.pyi | 0 third_party/{2and3 => 3}/geoip2/database.pyi | 0 third_party/{2and3 => 3}/geoip2/errors.pyi | 0 third_party/{2and3 => 3}/geoip2/mixins.pyi | 0 third_party/{2and3 => 3}/geoip2/models.pyi | 0 third_party/{2and3 => 3}/geoip2/records.pyi | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename third_party/{2and3 => 3}/geoip2/__init__.pyi (100%) rename third_party/{2and3 => 3}/geoip2/database.pyi (100%) rename third_party/{2and3 => 3}/geoip2/errors.pyi (100%) rename third_party/{2and3 => 3}/geoip2/mixins.pyi (100%) rename third_party/{2and3 => 3}/geoip2/models.pyi (100%) rename third_party/{2and3 => 3}/geoip2/records.pyi (100%) diff --git a/third_party/2and3/geoip2/__init__.pyi b/third_party/3/geoip2/__init__.pyi similarity index 100% rename from third_party/2and3/geoip2/__init__.pyi rename to third_party/3/geoip2/__init__.pyi diff --git a/third_party/2and3/geoip2/database.pyi b/third_party/3/geoip2/database.pyi similarity index 100% rename from third_party/2and3/geoip2/database.pyi rename to third_party/3/geoip2/database.pyi diff --git a/third_party/2and3/geoip2/errors.pyi b/third_party/3/geoip2/errors.pyi similarity index 100% rename from third_party/2and3/geoip2/errors.pyi rename to third_party/3/geoip2/errors.pyi diff --git a/third_party/2and3/geoip2/mixins.pyi b/third_party/3/geoip2/mixins.pyi similarity index 100% rename from third_party/2and3/geoip2/mixins.pyi rename to third_party/3/geoip2/mixins.pyi diff --git a/third_party/2and3/geoip2/models.pyi b/third_party/3/geoip2/models.pyi similarity index 100% rename from third_party/2and3/geoip2/models.pyi rename to third_party/3/geoip2/models.pyi diff --git a/third_party/2and3/geoip2/records.pyi b/third_party/3/geoip2/records.pyi similarity index 100% rename from third_party/2and3/geoip2/records.pyi rename to third_party/3/geoip2/records.pyi From 13fc3eb7ba1ee87ea604e28a2c3d3ba60be9977a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 8 Oct 2019 06:05:30 +0300 Subject: [PATCH 4/9] Moved maxminddb and geoip2 stubs to 2and3 --- third_party/{3 => 2and3}/geoip2/__init__.pyi | 0 third_party/{3 => 2and3}/geoip2/database.pyi | 0 third_party/{3 => 2and3}/geoip2/errors.pyi | 0 third_party/{3 => 2and3}/geoip2/mixins.pyi | 3 --- third_party/{3 => 2and3}/geoip2/models.pyi | 2 +- third_party/{3 => 2and3}/geoip2/records.pyi | 2 -- third_party/2and3/maxminddb/__init__.pyi | 9 +++++++++ third_party/{3 => 2and3}/maxminddb/compat.pyi | 2 +- third_party/{3 => 2and3}/maxminddb/const.pyi | 2 +- third_party/{3 => 2and3}/maxminddb/decoder.pyi | 2 +- third_party/{3 => 2and3}/maxminddb/errors.pyi | 2 +- third_party/{3 => 2and3}/maxminddb/extension.pyi | 10 +++++----- third_party/{3 => 2and3}/maxminddb/reader.pyi | 14 +++++++------- third_party/3/maxminddb/__init__.pyi | 9 --------- 14 files changed, 26 insertions(+), 31 deletions(-) rename third_party/{3 => 2and3}/geoip2/__init__.pyi (100%) rename third_party/{3 => 2and3}/geoip2/database.pyi (100%) rename third_party/{3 => 2and3}/geoip2/errors.pyi (100%) rename third_party/{3 => 2and3}/geoip2/mixins.pyi (77%) rename third_party/{3 => 2and3}/geoip2/models.pyi (98%) rename third_party/{3 => 2and3}/geoip2/records.pyi (97%) create mode 100644 third_party/2and3/maxminddb/__init__.pyi rename third_party/{3 => 2and3}/maxminddb/compat.pyi (84%) rename third_party/{3 => 2and3}/maxminddb/const.pyi (74%) rename third_party/{3 => 2and3}/maxminddb/decoder.pyi (82%) rename third_party/{3 => 2and3}/maxminddb/errors.pyi (50%) rename third_party/{3 => 2and3}/maxminddb/extension.pyi (79%) rename third_party/{3 => 2and3}/maxminddb/reader.pyi (65%) delete mode 100644 third_party/3/maxminddb/__init__.pyi diff --git a/third_party/3/geoip2/__init__.pyi b/third_party/2and3/geoip2/__init__.pyi similarity index 100% rename from third_party/3/geoip2/__init__.pyi rename to third_party/2and3/geoip2/__init__.pyi diff --git a/third_party/3/geoip2/database.pyi b/third_party/2and3/geoip2/database.pyi similarity index 100% rename from third_party/3/geoip2/database.pyi rename to third_party/2and3/geoip2/database.pyi diff --git a/third_party/3/geoip2/errors.pyi b/third_party/2and3/geoip2/errors.pyi similarity index 100% rename from third_party/3/geoip2/errors.pyi rename to third_party/2and3/geoip2/errors.pyi diff --git a/third_party/3/geoip2/mixins.pyi b/third_party/2and3/geoip2/mixins.pyi similarity index 77% rename from third_party/3/geoip2/mixins.pyi rename to third_party/2and3/geoip2/mixins.pyi index a3ca62986c16..4b338b234c2b 100644 --- a/third_party/3/geoip2/mixins.pyi +++ b/third_party/2and3/geoip2/mixins.pyi @@ -1,8 +1,5 @@ # Stubs for geoip2.mixins (Python 2 and 3) -from typing import Any - class SimpleEquality: - __metaclass__: Any def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... diff --git a/third_party/3/geoip2/models.pyi b/third_party/2and3/geoip2/models.pyi similarity index 98% rename from third_party/3/geoip2/models.pyi rename to third_party/2and3/geoip2/models.pyi index c6c832302ad6..08287c9ae42b 100644 --- a/third_party/3/geoip2/models.pyi +++ b/third_party/2and3/geoip2/models.pyi @@ -31,7 +31,7 @@ class Insights(City): ... class Enterprise(City): ... class SimpleModel(SimpleEquality): - __metaclass__: Any + pass class AnonymousIP(SimpleModel): is_anonymous: bool diff --git a/third_party/3/geoip2/records.pyi b/third_party/2and3/geoip2/records.pyi similarity index 97% rename from third_party/3/geoip2/records.pyi rename to third_party/2and3/geoip2/records.pyi index aaeec8c6a38b..0ede031775e5 100644 --- a/third_party/3/geoip2/records.pyi +++ b/third_party/2and3/geoip2/records.pyi @@ -8,12 +8,10 @@ _Locales = Optional[Sequence[Text]] _Names = Mapping[Text, Text] class Record(SimpleEquality): - __metaclass__: Any def __init__(self, **kwargs: Any) -> None: ... def __setattr__(self, name: Text, value: Any) -> None: ... class PlaceRecord(Record): - __metaclass__: Any def __init__(self, locales: _Locales = ..., **kwargs: Any) -> None: ... @property def name(self) -> Text: ... diff --git a/third_party/2and3/maxminddb/__init__.pyi b/third_party/2and3/maxminddb/__init__.pyi new file mode 100644 index 000000000000..246f51e03d65 --- /dev/null +++ b/third_party/2and3/maxminddb/__init__.pyi @@ -0,0 +1,9 @@ +# Stubs for maxminddb (Python 2 and 3) + +from typing import Any, Text + +from maxminddb import reader + +def open_database(database: Text, mode: int = ...) -> reader.Reader: ... + +def Reader(database: Text) -> reader.Reader: ... diff --git a/third_party/3/maxminddb/compat.pyi b/third_party/2and3/maxminddb/compat.pyi similarity index 84% rename from third_party/3/maxminddb/compat.pyi rename to third_party/2and3/maxminddb/compat.pyi index 236b0797ea94..05021675b11d 100644 --- a/third_party/3/maxminddb/compat.pyi +++ b/third_party/2and3/maxminddb/compat.pyi @@ -1,4 +1,4 @@ -# Stubs for maxminddb.compat (Python 3) +# Stubs for maxminddb.compat (Python 2 and 3) from ipaddress import IPv4Address, IPv6Address diff --git a/third_party/3/maxminddb/const.pyi b/third_party/2and3/maxminddb/const.pyi similarity index 74% rename from third_party/3/maxminddb/const.pyi rename to third_party/2and3/maxminddb/const.pyi index 36d11a7fa55f..ef42a80ec07d 100644 --- a/third_party/3/maxminddb/const.pyi +++ b/third_party/2and3/maxminddb/const.pyi @@ -1,4 +1,4 @@ -# Stubs for maxminddb.const (Python 3) +# Stubs for maxminddb.const (Python 2 and 3) MODE_AUTO: int = ... MODE_MMAP_EXT: int = ... diff --git a/third_party/3/maxminddb/decoder.pyi b/third_party/2and3/maxminddb/decoder.pyi similarity index 82% rename from third_party/3/maxminddb/decoder.pyi rename to third_party/2and3/maxminddb/decoder.pyi index 1b7aa6e154a6..f8b8b80f99a2 100644 --- a/third_party/3/maxminddb/decoder.pyi +++ b/third_party/2and3/maxminddb/decoder.pyi @@ -1,4 +1,4 @@ -# Stubs for maxminddb.decoder (Python 3) +# Stubs for maxminddb.decoder (Python 2 and 3) from typing import Any, Tuple diff --git a/third_party/3/maxminddb/errors.pyi b/third_party/2and3/maxminddb/errors.pyi similarity index 50% rename from third_party/3/maxminddb/errors.pyi rename to third_party/2and3/maxminddb/errors.pyi index 46b1f5aee972..f1bd887cfd36 100644 --- a/third_party/3/maxminddb/errors.pyi +++ b/third_party/2and3/maxminddb/errors.pyi @@ -1,3 +1,3 @@ -# Stubs for maxminddb.errors (Python 3) +# Stubs for maxminddb.errors (Python 2 and 3) class InvalidDatabaseError(RuntimeError): ... diff --git a/third_party/3/maxminddb/extension.pyi b/third_party/2and3/maxminddb/extension.pyi similarity index 79% rename from third_party/3/maxminddb/extension.pyi rename to third_party/2and3/maxminddb/extension.pyi index 24fb851803f3..f65bbb66e67c 100644 --- a/third_party/3/maxminddb/extension.pyi +++ b/third_party/2and3/maxminddb/extension.pyi @@ -1,6 +1,6 @@ -# Stubs for maxminddb.extension (Python 3) +# Stubs for maxminddb.extension (Python 2 and 3) -from typing import Any, Mapping, Sequence +from typing import Any, Mapping, Sequence, Text from maxminddb.errors import InvalidDatabaseError as InvalidDatabaseError @@ -21,9 +21,9 @@ class extension: @property def ip_version(self) -> int: ... @property - def database_type(self) -> str: ... + def database_type(self) -> Text: ... @property - def languages(self) -> Sequence[str]: ... + def languages(self) -> Sequence[Text]: ... @property def binary_format_major_version(self) -> int: ... @property @@ -31,5 +31,5 @@ class extension: @property def build_epoch(self) -> int: ... @property - def description(self) -> Mapping[str, str]: ... + def description(self) -> Mapping[Text, Text]: ... def __init__(self, **kwargs: Any) -> None: ... diff --git a/third_party/3/maxminddb/reader.pyi b/third_party/2and3/maxminddb/reader.pyi similarity index 65% rename from third_party/3/maxminddb/reader.pyi rename to third_party/2and3/maxminddb/reader.pyi index 47e7f6493a8f..e872d8a82c55 100644 --- a/third_party/3/maxminddb/reader.pyi +++ b/third_party/2and3/maxminddb/reader.pyi @@ -1,16 +1,16 @@ -# Stubs for maxminddb.reader (Python 3) +# Stubs for maxminddb.reader (Python 2 and 3) from ipaddress import IPv4Address, IPv6Address from types import TracebackType -from typing import Any, Mapping, Optional, Sequence, Tuple, Type, Union +from typing import Any, Mapping, Optional, Sequence, Text, Tuple, Type, Union class Reader: closed: bool = ... def __init__(self, database: bytes, mode: int = ...) -> None: ... def metadata(self) -> Metadata: ... - def get(self, ip_address: Union[str, IPv4Address, IPv6Address]) -> Optional[Any]: ... - def get_with_prefix_len(self, ip_address: Union[str, IPv4Address, IPv6Address]) -> Tuple[Optional[Any], int]: ... + def get(self, ip_address: Union[Text, IPv4Address, IPv6Address]) -> Optional[Any]: ... + def get_with_prefix_len(self, ip_address: Union[Text, IPv4Address, IPv6Address]) -> Tuple[Optional[Any], int]: ... def close(self) -> None: ... def __enter__(self) -> Reader: ... def __exit__(self, exc_type: Optional[Type[BaseException]] = ..., exc_val: Optional[BaseException] = ..., exc_tb: Optional[TracebackType] = ...) -> None: ... @@ -19,12 +19,12 @@ class Metadata: node_count: int = ... record_size: int = ... ip_version: int = ... - database_type: str = ... - languages: Sequence[str] = ... + database_type: Text = ... + languages: Sequence[Text] = ... binary_format_major_version: int = ... binary_format_minor_version: int = ... build_epoch: int = ... - description: Mapping[str, str] = ... + description: Mapping[Text, Text] = ... def __init__(self, **kwargs: Any) -> None: ... @property def node_byte_size(self) -> int: ... diff --git a/third_party/3/maxminddb/__init__.pyi b/third_party/3/maxminddb/__init__.pyi deleted file mode 100644 index 040872fed4ec..000000000000 --- a/third_party/3/maxminddb/__init__.pyi +++ /dev/null @@ -1,9 +0,0 @@ -# Stubs for maxminddb (Python 3) - -from typing import Any - -from maxminddb import reader - -def open_database(database: str, mode: int = ...) -> reader.Reader: ... - -def Reader(database: str) -> reader.Reader: ... From 7ae438727b669351877b11cd5c241c3481b6c7a1 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 8 Oct 2019 06:15:41 +0300 Subject: [PATCH 5/9] Fixed for flake8 --- third_party/2and3/geoip2/models.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/third_party/2and3/geoip2/models.pyi b/third_party/2and3/geoip2/models.pyi index 08287c9ae42b..569eaa6b9e1c 100644 --- a/third_party/2and3/geoip2/models.pyi +++ b/third_party/2and3/geoip2/models.pyi @@ -30,8 +30,7 @@ class Insights(City): ... class Enterprise(City): ... -class SimpleModel(SimpleEquality): - pass +class SimpleModel(SimpleEquality): ... class AnonymousIP(SimpleModel): is_anonymous: bool From 933fe429de93f666c9b734943431e14c27d01499 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 8 Oct 2019 06:16:08 +0300 Subject: [PATCH 6/9] Removed extra import --- third_party/2and3/maxminddb/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/maxminddb/__init__.pyi b/third_party/2and3/maxminddb/__init__.pyi index 246f51e03d65..c8345d19d005 100644 --- a/third_party/2and3/maxminddb/__init__.pyi +++ b/third_party/2and3/maxminddb/__init__.pyi @@ -1,6 +1,6 @@ # Stubs for maxminddb (Python 2 and 3) -from typing import Any, Text +from typing import Text from maxminddb import reader From b46a1af4ece8c76b7284b5deb5182f60ecbe60f0 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Tue, 8 Oct 2019 06:16:56 +0300 Subject: [PATCH 7/9] Copied stdlib ipaddress to thirdparty/2 for Python 2 --- third_party/2/ipaddress.pyi | 149 ++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 third_party/2/ipaddress.pyi diff --git a/third_party/2/ipaddress.pyi b/third_party/2/ipaddress.pyi new file mode 100644 index 000000000000..6b6a45d1d48a --- /dev/null +++ b/third_party/2/ipaddress.pyi @@ -0,0 +1,149 @@ +from typing import (Any, Container, Generic, Iterable, Iterator, Optional, + overload, SupportsInt, Text, Tuple, TypeVar) + +# Undocumented length constants +IPV4LENGTH: int +IPV6LENGTH: int + +_A = TypeVar("_A", IPv4Address, IPv6Address) +_N = TypeVar("_N", IPv4Network, IPv6Network) +_T = TypeVar("_T") + +def ip_address(address: object) -> Any: ... # morally Union[IPv4Address, IPv6Address] +def ip_network(address: object, strict: bool = ...) -> Any: ... # morally Union[IPv4Network, IPv6Network] +def ip_interface(address: object) -> Any: ... # morally Union[IPv4Interface, IPv6Interface] + +class _IPAddressBase: + def __eq__(self, other: Any) -> bool: ... + def __ge__(self: _T, other: _T) -> bool: ... + def __gt__(self: _T, other: _T) -> bool: ... + def __le__(self: _T, other: _T) -> bool: ... + def __lt__(self: _T, other: _T) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + @property + def compressed(self) -> Text: ... + @property + def exploded(self) -> Text: ... + @property + def reverse_pointer(self) -> Text: ... + @property + def version(self) -> int: ... + +class _BaseAddress(_IPAddressBase, SupportsInt): + def __init__(self, address: object) -> None: ... + def __add__(self: _T, other: int) -> _T: ... + def __hash__(self) -> int: ... + def __int__(self) -> int: ... + def __sub__(self: _T, other: int) -> _T: ... + @property + def is_global(self) -> bool: ... + @property + def is_link_local(self) -> bool: ... + @property + def is_loopback(self) -> bool: ... + @property + def is_multicast(self) -> bool: ... + @property + def is_private(self) -> bool: ... + @property + def is_reserved(self) -> bool: ... + @property + def is_unspecified(self) -> bool: ... + @property + def max_prefixlen(self) -> int: ... + @property + def packed(self) -> bytes: ... + +class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): + network_address: _A + netmask: _A + def __init__(self, address: object, strict: bool = ...) -> None: ... + def __contains__(self, other: Any) -> bool: ... + def __getitem__(self, n: int) -> _A: ... + def __iter__(self) -> Iterator[_A]: ... + def address_exclude(self: _T, other: _T) -> Iterator[_T]: ... + @property + def broadcast_address(self) -> _A: ... + def compare_networks(self: _T, other: _T) -> int: ... + def hosts(self) -> Iterator[_A]: ... + @property + def is_global(self) -> bool: ... + @property + def is_link_local(self) -> bool: ... + @property + def is_loopback(self) -> bool: ... + @property + def is_multicast(self) -> bool: ... + @property + def is_private(self) -> bool: ... + @property + def is_reserved(self) -> bool: ... + @property + def is_unspecified(self) -> bool: ... + @property + def max_prefixlen(self) -> int: ... + @property + def num_addresses(self) -> int: ... + def overlaps(self: _T, other: _T) -> bool: ... + @property + def prefixlen(self) -> int: ... + def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ... + def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> _T: ... + @property + def with_hostmask(self) -> Text: ... + @property + def with_netmask(self) -> Text: ... + @property + def with_prefixlen(self) -> Text: ... + @property + def hostmask(self) -> _A: ... + +class _BaseInterface(_BaseAddress, Generic[_A, _N]): + hostmask: _A + netmask: _A + network: _N + @property + def ip(self) -> _A: ... + @property + def with_hostmask(self) -> Text: ... + @property + def with_netmask(self) -> Text: ... + @property + def with_prefixlen(self) -> Text: ... + +class IPv4Address(_BaseAddress): ... +class IPv4Network(_BaseNetwork[IPv4Address]): ... +class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ... + +class IPv6Address(_BaseAddress): + @property + def ipv4_mapped(self) -> Optional[IPv4Address]: ... + @property + def is_site_local(self) -> bool: ... + @property + def sixtofour(self) -> Optional[IPv4Address]: ... + @property + def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ... + +class IPv6Network(_BaseNetwork[IPv6Address]): + @property + def is_site_local(self) -> bool: ... + +class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]): ... + +def v4_int_to_packed(address: int) -> bytes: ... +def v6_int_to_packed(address: int) -> bytes: ... +@overload +def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ... +@overload +def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ... +def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ... +@overload +def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ... +@overload +def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ... +@overload +def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ... + +class AddressValueError(ValueError): ... +class NetmaskValueError(ValueError): ... From d4c05f3fd2ffd004a9f5a4727478b833f86060ad Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 9 Oct 2019 19:03:11 +0300 Subject: [PATCH 8/9] Made stdlib/3/ipaddress.pyi and third_party/2/ipaddress.pyi consistent --- stdlib/3/ipaddress.pyi | 20 ++++++++++---------- tests/check_consistent.py | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/stdlib/3/ipaddress.pyi b/stdlib/3/ipaddress.pyi index 3d507f41b911..6b6a45d1d48a 100644 --- a/stdlib/3/ipaddress.pyi +++ b/stdlib/3/ipaddress.pyi @@ -1,5 +1,5 @@ from typing import (Any, Container, Generic, Iterable, Iterator, Optional, - overload, SupportsInt, Tuple, TypeVar) + overload, SupportsInt, Text, Tuple, TypeVar) # Undocumented length constants IPV4LENGTH: int @@ -21,11 +21,11 @@ class _IPAddressBase: def __lt__(self: _T, other: _T) -> bool: ... def __ne__(self, other: Any) -> bool: ... @property - def compressed(self) -> str: ... + def compressed(self) -> Text: ... @property - def exploded(self) -> str: ... + def exploded(self) -> Text: ... @property - def reverse_pointer(self) -> str: ... + def reverse_pointer(self) -> Text: ... @property def version(self) -> int: ... @@ -90,11 +90,11 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ... def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> _T: ... @property - def with_hostmask(self) -> str: ... + def with_hostmask(self) -> Text: ... @property - def with_netmask(self) -> str: ... + def with_netmask(self) -> Text: ... @property - def with_prefixlen(self) -> str: ... + def with_prefixlen(self) -> Text: ... @property def hostmask(self) -> _A: ... @@ -105,11 +105,11 @@ class _BaseInterface(_BaseAddress, Generic[_A, _N]): @property def ip(self) -> _A: ... @property - def with_hostmask(self) -> str: ... + def with_hostmask(self) -> Text: ... @property - def with_netmask(self) -> str: ... + def with_netmask(self) -> Text: ... @property - def with_prefixlen(self) -> str: ... + def with_prefixlen(self) -> Text: ... class IPv4Address(_BaseAddress): ... class IPv4Network(_BaseNetwork[IPv4Address]): ... diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 161cea2d84b7..afe81869bf6e 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -26,6 +26,7 @@ {'stdlib/3.7/dataclasses.pyi', 'third_party/3/dataclasses.pyi'}, {'stdlib/3/pathlib.pyi', 'third_party/2/pathlib2.pyi'}, {'stdlib/3.7/contextvars.pyi', 'third_party/3/contextvars.pyi'}, + {'stdlib/3/ipaddress.pyi', 'third_party/2/ipaddress.pyi'}, ] def main(): From d185521c92ad3c493f42effd6b3b49b43472d90a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Wed, 9 Oct 2019 19:03:23 +0300 Subject: [PATCH 9/9] Removed extra comments --- third_party/2and3/geoip2/database.pyi | 2 -- third_party/2and3/geoip2/errors.pyi | 2 -- third_party/2and3/geoip2/mixins.pyi | 2 -- third_party/2and3/geoip2/models.pyi | 2 -- third_party/2and3/geoip2/records.pyi | 2 -- third_party/2and3/maxminddb/__init__.pyi | 2 -- third_party/2and3/maxminddb/compat.pyi | 2 -- third_party/2and3/maxminddb/const.pyi | 2 -- third_party/2and3/maxminddb/decoder.pyi | 2 -- third_party/2and3/maxminddb/errors.pyi | 2 -- third_party/2and3/maxminddb/extension.pyi | 2 -- third_party/2and3/maxminddb/reader.pyi | 2 -- 12 files changed, 24 deletions(-) diff --git a/third_party/2and3/geoip2/database.pyi b/third_party/2and3/geoip2/database.pyi index e55adf4cba27..7a8991160162 100644 --- a/third_party/2and3/geoip2/database.pyi +++ b/third_party/2and3/geoip2/database.pyi @@ -1,5 +1,3 @@ -# Stubs for geoip2.database (Python 2 and 3) - from types import TracebackType from typing import Optional, Sequence, Text, Type diff --git a/third_party/2and3/geoip2/errors.pyi b/third_party/2and3/geoip2/errors.pyi index c12f60a054f4..d5b703c30432 100644 --- a/third_party/2and3/geoip2/errors.pyi +++ b/third_party/2and3/geoip2/errors.pyi @@ -1,5 +1,3 @@ -# Stubs for geoip2.errors (Python 2 and 3) - from typing import Optional, Text class GeoIP2Error(RuntimeError): ... diff --git a/third_party/2and3/geoip2/mixins.pyi b/third_party/2and3/geoip2/mixins.pyi index 4b338b234c2b..8c683c26b84b 100644 --- a/third_party/2and3/geoip2/mixins.pyi +++ b/third_party/2and3/geoip2/mixins.pyi @@ -1,5 +1,3 @@ -# Stubs for geoip2.mixins (Python 2 and 3) - class SimpleEquality: def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... diff --git a/third_party/2and3/geoip2/models.pyi b/third_party/2and3/geoip2/models.pyi index 569eaa6b9e1c..d9330ef8f428 100644 --- a/third_party/2and3/geoip2/models.pyi +++ b/third_party/2and3/geoip2/models.pyi @@ -1,5 +1,3 @@ -# Stubs for geoip2.models (Python 2 and 3) - from typing import Any, Mapping, Optional, Sequence, Text from geoip2 import records diff --git a/third_party/2and3/geoip2/records.pyi b/third_party/2and3/geoip2/records.pyi index 0ede031775e5..0d90b18ca449 100644 --- a/third_party/2and3/geoip2/records.pyi +++ b/third_party/2and3/geoip2/records.pyi @@ -1,5 +1,3 @@ -# Stubs for geoip2.records (Python 2 and 3) - from typing import Any, Mapping, Optional, Sequence, Text, Tuple from geoip2.mixins import SimpleEquality diff --git a/third_party/2and3/maxminddb/__init__.pyi b/third_party/2and3/maxminddb/__init__.pyi index c8345d19d005..fe20a1f42cd1 100644 --- a/third_party/2and3/maxminddb/__init__.pyi +++ b/third_party/2and3/maxminddb/__init__.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb (Python 2 and 3) - from typing import Text from maxminddb import reader diff --git a/third_party/2and3/maxminddb/compat.pyi b/third_party/2and3/maxminddb/compat.pyi index 05021675b11d..ca8e3ab2c78f 100644 --- a/third_party/2and3/maxminddb/compat.pyi +++ b/third_party/2and3/maxminddb/compat.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb.compat (Python 2 and 3) - from ipaddress import IPv4Address, IPv6Address from typing import Any diff --git a/third_party/2and3/maxminddb/const.pyi b/third_party/2and3/maxminddb/const.pyi index ef42a80ec07d..e1cff069a10a 100644 --- a/third_party/2and3/maxminddb/const.pyi +++ b/third_party/2and3/maxminddb/const.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb.const (Python 2 and 3) - MODE_AUTO: int = ... MODE_MMAP_EXT: int = ... MODE_MMAP: int = ... diff --git a/third_party/2and3/maxminddb/decoder.pyi b/third_party/2and3/maxminddb/decoder.pyi index f8b8b80f99a2..e2bc38adb604 100644 --- a/third_party/2and3/maxminddb/decoder.pyi +++ b/third_party/2and3/maxminddb/decoder.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb.decoder (Python 2 and 3) - from typing import Any, Tuple class Decoder: diff --git a/third_party/2and3/maxminddb/errors.pyi b/third_party/2and3/maxminddb/errors.pyi index f1bd887cfd36..e98b5560d027 100644 --- a/third_party/2and3/maxminddb/errors.pyi +++ b/third_party/2and3/maxminddb/errors.pyi @@ -1,3 +1 @@ -# Stubs for maxminddb.errors (Python 2 and 3) - class InvalidDatabaseError(RuntimeError): ... diff --git a/third_party/2and3/maxminddb/extension.pyi b/third_party/2and3/maxminddb/extension.pyi index f65bbb66e67c..de4423c34ac6 100644 --- a/third_party/2and3/maxminddb/extension.pyi +++ b/third_party/2and3/maxminddb/extension.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb.extension (Python 2 and 3) - from typing import Any, Mapping, Sequence, Text from maxminddb.errors import InvalidDatabaseError as InvalidDatabaseError diff --git a/third_party/2and3/maxminddb/reader.pyi b/third_party/2and3/maxminddb/reader.pyi index e872d8a82c55..882a49876184 100644 --- a/third_party/2and3/maxminddb/reader.pyi +++ b/third_party/2and3/maxminddb/reader.pyi @@ -1,5 +1,3 @@ -# Stubs for maxminddb.reader (Python 2 and 3) - from ipaddress import IPv4Address, IPv6Address from types import TracebackType