Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing-only Mixin Class for Type Checking #2015

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions faker/providers/address/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ class Provider(BaseProvider):
address_formats: ElementsType[str] = ("{{street_address}} {{postcode}} {{city}}",)
building_number_formats: ElementsType[str] = ("##",)
postcode_formats: ElementsType[str] = ("#####",)
countries: ElementsType[str] = [country.name for country in date_time.Provider.countries]
countries: ElementsType[str] = [country.name for country in date_time.Provider.country_timezones]

ALPHA_2 = "alpha-2"
ALPHA_3 = "alpha-3"

alpha_2_country_codes: ElementsType[str] = [country.alpha_2_code for country in date_time.Provider.countries]
alpha_3_country_codes: ElementsType[str] = [country.alpha_3_code for country in date_time.Provider.countries]
alpha_2_country_codes: ElementsType[str] = [
country.alpha_2_code for country in date_time.Provider.country_timezones
]
alpha_3_country_codes: ElementsType[str] = [
country.alpha_3_code for country in date_time.Provider.country_timezones
]

def city_suffix(self) -> str:
"""
Expand Down Expand Up @@ -92,7 +96,9 @@ def current_country_code(self) -> str:
def current_country(self) -> str:
current_country_code = self.current_country_code()
current_country = [
country.name for country in date_time.Provider.countries if country.alpha_2_code == current_country_code
country.name
for country in date_time.Provider.country_timezones
if country.alpha_2_code == current_country_code
]
if len(current_country) == 1:
return current_country[0] # type: ignore
Expand Down
12 changes: 6 additions & 6 deletions faker/providers/bank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Provider(BaseProvider):

ALPHA: Dict[str, str] = {c: str(ord(c) % 55) for c in string.ascii_uppercase}
bban_format: str = "????#############"
country_code: str = "GB"
bank_country_code: str = "GB"

def aba(self) -> str:
"""Generate an ABA routing transit number."""
Expand All @@ -46,7 +46,7 @@ def aba(self) -> str:

def bank_country(self) -> str:
"""Generate the bank provider's ISO 3166-1 alpha-2 country code."""
return self.country_code
return self.bank_country_code

def bban(self) -> str:
"""Generate a Basic Bank Account Number (BBAN)."""
Expand All @@ -57,12 +57,12 @@ def iban(self) -> str:
"""Generate an International Bank Account Number (IBAN)."""
bban = self.bban()

check = bban + self.country_code + "00"
check = bban + self.bank_country_code + "00"
check_ = int("".join(self.ALPHA.get(c, c) for c in check))
check_ = 98 - (check_ % 97)
check = str(check_).zfill(2)

return self.country_code + check + bban
return self.bank_country_code + check + bban

def swift8(self, use_dataset: bool = False) -> str:
"""Generate an 8-digit SWIFT code.
Expand Down Expand Up @@ -143,7 +143,7 @@ def swift(
location_code = self.lexify("??", letters=string.ascii_uppercase + string.digits)

if length == 8:
return bank_code + self.country_code + location_code
return bank_code + self.bank_country_code + location_code

if primary:
branch_code = "XXX"
Expand All @@ -152,4 +152,4 @@ def swift(
else:
branch_code = self.lexify("???", letters=string.ascii_uppercase + string.digits)

return bank_code + self.country_code + location_code + branch_code
return bank_code + self.bank_country_code + location_code + branch_code
2 changes: 1 addition & 1 deletion faker/providers/bank/az_AZ/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Provider(BankProvider):
"""Implement bank provider for ``az_AZ`` locale."""

bban_format = "????####################"
country_code = "AZ"
bank_country_code = "AZ"

banks = (
"AccessBank",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/bn_BD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Provider(BankProvider):
"""

bban_format: str = "????#########"
country_code = "BD"
bank_country_code = "BD"
swift_location_codes = ("DH",)
swift_branch_codes = (
"ABBL",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/cs_CZ/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class Provider(BankProvider):
"""

bban_format = "####################"
country_code = "CZ"
bank_country_code = "CZ"
2 changes: 1 addition & 1 deletion faker/providers/bank/da_DK/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``da_DK`` locale."""

bban_format = "################"
country_code = "DK"
bank_country_code = "DK"
2 changes: 1 addition & 1 deletion faker/providers/bank/de_AT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``de_AT`` locale."""

bban_format = "################"
country_code = "AT"
bank_country_code = "AT"
2 changes: 1 addition & 1 deletion faker/providers/bank/de_CH/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``de_CH`` locale."""

bban_format = "#################"
country_code = "CH"
bank_country_code = "CH"
2 changes: 1 addition & 1 deletion faker/providers/bank/de_DE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Provider(BankProvider):
"""

bban_format = "##################"
country_code = "DE"
bank_country_code = "DE"

first_place = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "23456789"
second_place = "ABCDEFGHIJKLMNPQRSTUVWXYZ" + "0123456789"
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/el_GR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``el_GR`` locale."""

bban_format = "#######################"
country_code = "GR"
bank_country_code = "GR"
2 changes: 1 addition & 1 deletion faker/providers/bank/en_GB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``en_GB`` locale."""

bban_format = "????##############"
country_code = "GB"
bank_country_code = "GB"
2 changes: 1 addition & 1 deletion faker/providers/bank/en_IE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``en_IE`` locale."""

bban_format = "#######################"
country_code = "IE"
bank_country_code = "IE"
2 changes: 1 addition & 1 deletion faker/providers/bank/en_PH/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Provider(BankProvider):
"""Implement bank provider for ``en_PH`` locale."""

country_code = "PH"
bank_country_code = "PH"
bban_format = "################"
swift_bank_codes = (
"ANZB",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/es_AR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Provider(BankProvider):
source: https://www.bcra.gob.ar/SistemasFinancierosYdePagos/Activos.asp"""

bban_format = "????####################"
country_code = "AR"
bank_country_code = "AR"

banks = (
"Banco de la Nación Argentina",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/es_ES/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``es_ES`` locale."""

bban_format = "####################"
country_code = "ES"
bank_country_code = "ES"
2 changes: 1 addition & 1 deletion faker/providers/bank/fa_IR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Provider(BankProvider):
"""Implement bank provider for ``fa_IR`` locale."""

bban_format = "IR########################"
country_code = "IR"
bank_country_code = "IR"
swift_bank_codes = (
"BEGN",
"KESH",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/fi_FI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``fi_FI`` locale."""

bban_format = "##############"
country_code = "FI"
bank_country_code = "FI"
2 changes: 1 addition & 1 deletion faker/providers/bank/fr_FR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``fr_FR`` locale."""

bban_format = "#######################"
country_code = "FR"
bank_country_code = "FR"
2 changes: 1 addition & 1 deletion faker/providers/bank/it_IT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``it_IT`` locale."""

bban_format = "?######################"
country_code = "IT"
bank_country_code = "IT"
2 changes: 1 addition & 1 deletion faker/providers/bank/nl_BE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Provider(BankProvider):
"""

bban_format = "############"
country_code = "BE"
bank_country_code = "BE"

banks = (
"Argenta Spaarbank",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/nl_NL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``nl_NL`` locale."""

bban_format = "????##########"
country_code = "NL"
bank_country_code = "NL"
2 changes: 1 addition & 1 deletion faker/providers/bank/no_NO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``no_NO`` locale."""

bban_format = "###########"
country_code = "NO"
bank_country_code = "NO"
2 changes: 1 addition & 1 deletion faker/providers/bank/pl_PL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``pl_PL`` locale."""

bban_format = "#" * 24
country_code = "PL"
bank_country_code = "PL"
2 changes: 1 addition & 1 deletion faker/providers/bank/pt_PT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``pt_PT`` locale."""

bban_format = "#####################"
country_code = "PT"
bank_country_code = "PT"
2 changes: 1 addition & 1 deletion faker/providers/bank/ro_RO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Provider(BankProvider):
"""Implement bank provider for ``ro_RO`` locale."""

country_code = "RO"
bank_country_code = "RO"
bban_format = "????################"
swift_bank_codes = (
"NBOR",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/ru_RU/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Provider(BankProvider):
- http://cbr.ru/credit/coreports/ko17012020.zip
"""

country_code = "RU"
bank_country_code = "RU"

region_codes = (
"01",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/sk_SK/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class Provider(BankProvider):
"""

bban_format = "####################"
country_code = "SK"
bank_country_code = "SK"
2 changes: 1 addition & 1 deletion faker/providers/bank/th_TH/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Provider(BankProvider):
"""Implement bank provider for ``th_TH`` locale."""

bban_format = "#" * 10
country_code = "TH"
bank_country_code = "TH"
swift_bank_codes = (
"AIAC",
"ANZB",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/bank/tr_TR/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ class Provider(BankProvider):
"""Implement bank provider for ``tr_TR`` locale."""

bban_format = "######################"
country_code = "TR"
bank_country_code = "TR"
2 changes: 1 addition & 1 deletion faker/providers/bank/uk_UA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Provider(BankProvider):
"""

bban_format = "#" * 27
country_code = "UA"
bank_country_code = "UA"
banks = (
"izibank",
"monobank",
Expand Down
4 changes: 2 additions & 2 deletions faker/providers/date_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _rand_seconds(self, start_datetime: int, end_datetime: int) -> float:
"XXI",
]

countries = [
country_timezones: list[Country] = [
Country(
timezones=["Europe/Andorra"],
alpha_2_code="AD",
Expand Down Expand Up @@ -2444,7 +2444,7 @@ def century(self) -> str:
return self.random_element(self.centuries)

def timezone(self) -> str:
return self.generator.random.choice(self.random_element(self.countries).timezones) # type: ignore
return self.generator.random.choice(self.random_element(self.country_timezones).timezones) # type: ignore

def pytimezone(self, *args: Any, **kwargs: Any) -> Optional[TzInfo]:
"""
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/date_time/ar_AA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Provider(DateTimeProvider):
"الثاني والعشرين",
]

countries = [
country_timezones = [
Country(
timezones=["أوروب/أندورا"],
alpha_2_code="AD",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/date_time/bn_BD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Provider(DateTimeProvider):
"12": "ডিসেম্বর",
}

countries = [
country_timezones = [
Country(
timezones=["ইউরোপ/অ্যান্ডোরা"],
alpha_2_code="AD",
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/date_time/ru_RU/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Provider(DateTimeProvider):
}

# Timezone names are based on Wiki list, source: https://ru.wikipedia.org/wiki/Список_часовых_поясов_по_странам
countries = [
country_timezones = [
Country(
timezones=["Андорра (UTC+01)"],
alpha_2_code="AD",
Expand Down
3 changes: 1 addition & 2 deletions faker/providers/isbn/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
https://www.isbn-international.org/range_file_generation
"""

from collections import namedtuple
from typing import Dict, List

RegistrantRule = namedtuple("RegistrantRule", ["min", "max", "registrant_length"])
from ...typing import RegistrantRule

# Structure: RULES[`EAN Prefix`][`Registration Group`] = [Rule1, Rule2, ...]
RULES: Dict[str, Dict[str, List[RegistrantRule]]] = {
Expand Down
Loading