|
13 | 13 | # pylint: disable=too-many-instance-attributes,too-few-public-methods |
14 | 14 | import ipaddress |
15 | 15 | from abc import ABCMeta |
16 | | -from typing import Any, Dict, List, Optional, Union |
| 16 | +from typing import Any, cast, Dict, List, Optional, Union |
17 | 17 |
|
18 | 18 | import geoip2.records |
19 | 19 | from geoip2.mixins import SimpleEquality |
@@ -67,6 +67,13 @@ class Country(SimpleEquality): |
67 | 67 |
|
68 | 68 | """ |
69 | 69 |
|
| 70 | + continent: geoip2.records.Continent |
| 71 | + country: geoip2.records.Country |
| 72 | + maxmind: geoip2.records.MaxMind |
| 73 | + registered_country: geoip2.records.Country |
| 74 | + represented_country: geoip2.records.RepresentedCountry |
| 75 | + traits: geoip2.records.Traits |
| 76 | + |
70 | 77 | def __init__( |
71 | 78 | self, raw_response: Dict[str, Any], locales: Optional[List[str]] = None |
72 | 79 | ) -> None: |
@@ -171,6 +178,11 @@ class City(Country): |
171 | 178 |
|
172 | 179 | """ |
173 | 180 |
|
| 181 | + city: geoip2.records.City |
| 182 | + location: geoip2.records.Location |
| 183 | + postal: geoip2.records.Postal |
| 184 | + subdivisions: geoip2.records.Subdivisions |
| 185 | + |
174 | 186 | def __init__( |
175 | 187 | self, raw_response: Dict[str, Any], locales: Optional[List[str]] = None |
176 | 188 | ) -> None: |
@@ -316,11 +328,14 @@ class SimpleModel(SimpleEquality): |
316 | 328 |
|
317 | 329 | __metaclass__ = ABCMeta |
318 | 330 |
|
| 331 | + raw: Dict[str, Union[bool, str, int]] |
| 332 | + ip_address: str |
| 333 | + |
319 | 334 | def __init__(self, raw: Dict[str, Union[bool, str, int]]) -> None: |
320 | 335 | self.raw = raw |
321 | 336 | self._network = None |
322 | 337 | self._prefix_len = raw.get("prefix_len") |
323 | | - self.ip_address = raw.get("ip_address") |
| 338 | + self.ip_address = cast(str, raw.get("ip_address")) |
324 | 339 |
|
325 | 340 | def __repr__(self) -> str: |
326 | 341 | # pylint: disable=no-member |
@@ -404,8 +419,14 @@ class AnonymousIP(SimpleModel): |
404 | 419 | :type: ipaddress.IPv4Network or ipaddress.IPv6Network |
405 | 420 | """ |
406 | 421 |
|
407 | | - def __init__(self, raw: Dict[str, Union[bool, str, int]]) -> None: |
408 | | - super(AnonymousIP, self).__init__(raw) |
| 422 | + is_anonymous: bool |
| 423 | + is_anonymous_vpn: bool |
| 424 | + is_hosting_provider: bool |
| 425 | + is_public_proxy: bool |
| 426 | + is_tor_exit_node: bool |
| 427 | + |
| 428 | + def __init__(self, raw: Dict[str, bool]) -> None: |
| 429 | + super(AnonymousIP, self).__init__(raw) # type: ignore |
409 | 430 | self.is_anonymous = raw.get("is_anonymous", False) |
410 | 431 | self.is_anonymous_vpn = raw.get("is_anonymous_vpn", False) |
411 | 432 | self.is_hosting_provider = raw.get("is_hosting_provider", False) |
@@ -446,11 +467,18 @@ class ASN(SimpleModel): |
446 | 467 | :type: ipaddress.IPv4Network or ipaddress.IPv6Network |
447 | 468 | """ |
448 | 469 |
|
| 470 | + autonomous_system_number: Optional[int] |
| 471 | + autonomous_system_organization: Optional[str] |
| 472 | + |
449 | 473 | # pylint:disable=too-many-arguments |
450 | 474 | def __init__(self, raw: Dict[str, Union[str, int]]) -> None: |
451 | 475 | super(ASN, self).__init__(raw) |
452 | | - self.autonomous_system_number = raw.get("autonomous_system_number") |
453 | | - self.autonomous_system_organization = raw.get("autonomous_system_organization") |
| 476 | + self.autonomous_system_number = cast( |
| 477 | + Optional[int], raw.get("autonomous_system_number") |
| 478 | + ) |
| 479 | + self.autonomous_system_organization = cast( |
| 480 | + Optional[str], raw.get("autonomous_system_organization") |
| 481 | + ) |
454 | 482 |
|
455 | 483 |
|
456 | 484 | class ConnectionType(SimpleModel): |
@@ -486,9 +514,11 @@ class ConnectionType(SimpleModel): |
486 | 514 | :type: ipaddress.IPv4Network or ipaddress.IPv6Network |
487 | 515 | """ |
488 | 516 |
|
| 517 | + connection_type: Optional[str] |
| 518 | + |
489 | 519 | def __init__(self, raw: Dict[str, Union[str, int]]) -> None: |
490 | 520 | super(ConnectionType, self).__init__(raw) |
491 | | - self.connection_type = raw.get("connection_type") |
| 521 | + self.connection_type = cast(Optional[str], raw.get("connection_type")) |
492 | 522 |
|
493 | 523 |
|
494 | 524 | class Domain(SimpleModel): |
@@ -518,9 +548,11 @@ class Domain(SimpleModel): |
518 | 548 |
|
519 | 549 | """ |
520 | 550 |
|
| 551 | + domain: Optional[str] |
| 552 | + |
521 | 553 | def __init__(self, raw: Dict[str, Union[str, int]]) -> None: |
522 | 554 | super(Domain, self).__init__(raw) |
523 | | - self.domain = raw.get("domain") |
| 555 | + self.domain = cast(Optional[str], raw.get("domain")) |
524 | 556 |
|
525 | 557 |
|
526 | 558 | class ISP(ASN): |
@@ -568,8 +600,11 @@ class ISP(ASN): |
568 | 600 | :type: ipaddress.IPv4Network or ipaddress.IPv6Network |
569 | 601 | """ |
570 | 602 |
|
| 603 | + isp: Optional[str] |
| 604 | + organization: Optional[str] |
| 605 | + |
571 | 606 | # pylint:disable=too-many-arguments |
572 | 607 | def __init__(self, raw: Dict[str, Union[str, int]]) -> None: |
573 | 608 | super(ISP, self).__init__(raw) |
574 | | - self.isp = raw.get("isp") |
575 | | - self.organization = raw.get("organization") |
| 609 | + self.isp = cast(Optional[str], raw.get("isp")) |
| 610 | + self.organization = cast(Optional[str], raw.get("organization")) |
0 commit comments