Skip to content

Commit

Permalink
fix typying for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante383 committed Nov 15, 2023
1 parent 9dffbb2 commit 93d3f52
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions trollfactory/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Functions used by the TrollFactory cli and library."""

from sys import modules
from typing import Optional, Any
from typing import Optional, Any, List

from trollfactory import props
from trollfactory.props import *
Expand All @@ -13,7 +13,7 @@
def generate_personality(
p_dataset: str = 'polish',
p_gender: str = 'female',
exclude_props: Optional[list[str]] = None) -> dict:
exclude_props: Optional[List[str]] = None) -> dict:
"""Generate a fake personality."""
exclude_props = exclude_props or []

Expand Down
4 changes: 2 additions & 2 deletions trollfactory/props/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Properties generation scripts used by the TrollFactory cli and library."""

__props__: list[str] = [
__props__ = [
'address',
'bank',
'birthdate',
Expand All @@ -18,4 +18,4 @@
'phone',
]

__all__: list[str] = __props__ + ['langs']
__all__ = __props__ + ['langs']
26 changes: 13 additions & 13 deletions trollfactory/props/address.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Address generation prop for TrollFactory."""

from random import choice, randint
from typing import Any, TypedDict
from typing import Any, TypedDict, Dict
from json import loads
from pkgutil import get_data

COUNTRY_CODES: dict[str, str] = {'polish': 'PL', 'english_us': 'US'}
COUNTRY_CODES: Dict[str, str] = {'polish': 'PL', 'english_us': 'US'}


class AddressType(TypedDict):
Expand All @@ -22,18 +22,18 @@ class AddressType(TypedDict):
street_number: int


def generate_region(language: str) -> dict[str, Any]:
def generate_region(language: str) -> Dict[str, Any]:
"""Generate a dict with region data."""
return choice(loads(get_data(
__package__, 'langs/'+language+'/cities.json')))


def generate_country_state(region: dict) -> str:
def generate_country_state(region: Dict) -> str:
"""Generate a region name."""
return region['region_name']


def generate_city(region: dict) -> dict[str, Any]:
def generate_city(region: dict) -> Dict[str, Any]:
"""Generate a dict with city data."""
return choice(region['cities'])

Expand All @@ -43,27 +43,27 @@ def generate_country_code(language: str) -> str:
return COUNTRY_CODES[language]


def generate_country_city(city: dict) -> str:
def generate_country_city(city: Dict) -> str:
"""Generate a city name."""
return city['name']


def generate_city_postcode(city: dict) -> str:
def generate_city_postcode(city: Dict) -> str:
"""Generate a postcode."""
return city['postcode']


def generate_city_street(city: dict) -> str:
def generate_city_street(city: Dict) -> str:
"""Generate a street name."""
return choice(city['streets'])


def generate_city_latitude(city: dict) -> float:
def generate_city_latitude(city: Dict) -> float:
"""Generate a latitude."""
return city['lat']


def generate_city_longitude(city: dict) -> float:
def generate_city_longitude(city: Dict) -> float:
"""Generate a longitude."""
return city['lon']

Expand All @@ -77,7 +77,7 @@ def generate_street_number() -> int:
class Address:
"""Address generation prop for TrollFactory."""

def __init__(self, properties: dict) -> None:
def __init__(self, properties: Dict) -> None:
self.properties = properties
self.unresolved_dependencies: tuple[str] = ('language',) if \
'language' not in properties else ()
Expand All @@ -92,9 +92,9 @@ def generate(self) -> AddressType:
return {'prop_title': 'Address', 'country_code': 'US'}

# Generate data
region: dict[str, Any] = generate_region(language)
region: Dict[str, Any] = generate_region(language)
country_state: str = generate_country_state(region)
city: dict[str, Any] = generate_city(region)
city: Dict[str, Any] = generate_city(region)
city_street: str = generate_city_street(city)
country_code: str = generate_country_code(language)
country_city: str = generate_country_city(city)
Expand Down
4 changes: 2 additions & 2 deletions trollfactory/props/birthdate.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Birthdate generation prop for TrollFactory."""

from typing import TypedDict
from typing import TypedDict, Tuple
from random import choice, randint
from calendar import monthrange
from datetime import date


ZODIAC_SIGNS: tuple[tuple[str, int, int, int]] = (
ZODIAC_SIGNS: Tuple[Tuple[str, int, int, int]] = (
('Aries', 18, 4, 13, 5),
('Taurus', 13, 5, 21, 6),
('Gemini', 21, 6, 20, 7),
Expand Down
14 changes: 7 additions & 7 deletions trollfactory/props/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from random import choice, choices, randint
from pkgutil import get_data
from typing import Optional, Any, TypedDict
from typing import Optional, Any, TypedDict, Dict
from json import loads


Expand Down Expand Up @@ -80,32 +80,32 @@ def generate_plate_number(language: str, country_state: str) -> Optional[str]:
return prefix + ' ' + plate_resource


def generate_brand(age: int, dataset: dict) -> Optional[dict[str, Any]]:
def generate_brand(age: int, dataset: dict) -> Optional[Dict[str, Any]]:
"""Generate a dict with car brand data."""
if age in range(14, 17):
return None
return choices(dataset, [i['brand_weight'] for i in dataset])[0]


def generate_brand_name(age: int, brand: Optional[dict]) -> str:
def generate_brand_name(age: int, brand: Optional[Dict]) -> str:
"""Generate a car brand."""
if age in range(14, 17):
return choice(('Aixam', 'Ligier', 'Microcar', 'Chatenet'))
return brand['brand_name']


def generate_model(brand_name: str, dataset: dict) -> dict[str, Any]:
def generate_model(brand_name: str, dataset: dict) -> Dict[str, Any]:
"""Generate a dict with car model data."""
return choice([i for i in dataset if i['brand_name'] == brand_name
][0]['models'])


def generate_model_name(model: dict[str, Any]) -> str:
def generate_model_name(model: Dict[str, Any]) -> str:
"""Generate a car model name."""
return model['name']


def generate_generation_name(age: int, model: dict[str, Any]) -> Optional[str]:
def generate_generation_name(age: int, model: Dict[str, Any]) -> Optional[str]:
"""Generate a car generation name."""
if age in range(14, 17):
return None
Expand All @@ -118,7 +118,7 @@ def generate_generation_name(age: int, model: dict[str, Any]) -> Optional[str]:
class Car:
"""Car data generation prop for TrollFactory."""

def __init__(self, properties: dict) -> None:
def __init__(self, properties: Dict) -> None:
self.properties = properties
self.unresolved_dependencies: list[str] = []

Expand Down
4 changes: 2 additions & 2 deletions trollfactory/props/cc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Credit card data generation prop for TrollFactory."""

from typing import Optional, TypedDict
from typing import Optional, TypedDict, Dict, Tuple
from random import randint, choice


CARD_TYPES: dict[str, tuple[tuple[str], int]] = {
CARD_TYPES: Dict[str, Tuple[Tuple[str], int]] = {
'americanexpress': (('34', '37'), 15),
'diners': (('300', '301', '302', '303', '304', '305', '36', '38', '39'),
14),
Expand Down
6 changes: 3 additions & 3 deletions trollfactory/props/colors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Colors data generation prop for TrollFactory."""

from random import choice
from typing import TypedDict
from typing import TypedDict, Dict, Tuple

COLORS: dict[str, tuple[str]] = {
COLORS: Dict[str, Tuple[str]] = {
'favourite': ('black', 'white', 'grey', 'red', 'blue', 'navy', 'green',
'pink', 'white', 'purple', 'yellow', 'green', 'orange'),
'hair': ('blonde', 'brown', 'black', 'auburn', 'red'),
Expand Down Expand Up @@ -40,7 +40,7 @@ class Colors:

def __init__(self, properties: dict) -> None:
self.properties = properties
self.unresolved_dependencies: tuple[str] = ()
self.unresolved_dependencies: Tuple[str] = ()

def generate(self) -> ColorsType:
"""Generate the colors data."""
Expand Down
2 changes: 1 addition & 1 deletion trollfactory/props/langs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Datasets used by the TrollFactory cli and library."""

__all__: list[str] = [
__all__ = [
'polish',
'english_us',
]
6 changes: 3 additions & 3 deletions trollfactory/props/measurements.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Measurements generation prop for TrollFactory."""

from typing import TypedDict
from typing import TypedDict, Dict, Tuple
from random import randint

AVERAGES: dict[int, tuple[int, int, int, int]] = {
AVERAGES: Dict[int, Tuple[int, int, int, int]] = {
0: (5, 10, 50, 90), 1: (5, 10, 50, 90), 2: (10, 16, 80, 95),
3: (12, 20, 89, 102), 4: (13, 22, 90, 113), 5: (15, 25, 102, 120),
6: (16, 29, 107, 129), 7: (18, 34, 113, 135), 8: (20, 41, 119, 141),
Expand Down Expand Up @@ -47,7 +47,7 @@ class Measurements:

def __init__(self, properties: dict) -> None:
self.properties = properties
self.unresolved_dependencies: tuple[str] = ('birthdate',) if \
self.unresolved_dependencies: Tuple[str] = ('birthdate',) if \
'birthdate' not in properties else ()

def generate(self) -> MeasurementsType:
Expand Down
8 changes: 4 additions & 4 deletions trollfactory/props/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from string import ascii_uppercase, ascii_lowercase, digits
from random import choice, randint
from pkgutil import get_data
from typing import Optional, TypedDict
from typing import Optional, TypedDict, Dict, Tuple
from json import loads

EMAIL_PROVIDERS: dict[str, tuple[str]] = {
EMAIL_PROVIDERS: Dict[str, Tuple[str]] = {
'polish': ('@niepodam.pl',),
'english_us': ('@armyspy.com', '@cuvox.de', '@dayrep.com', '@einrot.com',
'@gustr.com', '@jourrapide.com', '@rhyta.com',
'@superrito.com', '@teleworm.us'),
}

EMAIL_URLS: dict[str, str] = {
EMAIL_URLS: Dict[str, str] = {
'@niepodam.pl': 'http://niepodam.pl/users/',
'@armyspy.com': 'http://www.fakemailgenerator.com/#/armyspy.com/',
'@cuvox.de': 'http://www.fakemailgenerator.com/#/cuvox.de/',
Expand All @@ -26,7 +26,7 @@
'@teleworm.us': 'http://www.fakemailgenerator.com/#/teleworm.us/',
}

TLDS: tuple[str] = ('.pl', '.com', '.com.pl', '.net', '.biz', '.me')
TLDS: Tuple[str] = ('.pl', '.com', '.com.pl', '.net', '.biz', '.me')


class OnlineType(TypedDict):
Expand Down

0 comments on commit 93d3f52

Please sign in to comment.