Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Oct 16, 2024
1 parent 0ecfc2e commit 2ccb85a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion faker/providers/passport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from string import ascii_uppercase
from typing import Tuple

from faker.typing import SexLiteral

from .. import BaseProvider, ElementsType

localized = True
Expand All @@ -19,7 +21,7 @@ def passport_dob(self) -> datetime.date:
birthday = self.generator.date_of_birth()
return birthday

def passport_owner(self, gender: str = "X") -> Tuple[str, str]:
def passport_owner(self, gender: SexLiteral = "X") -> Tuple[str, str]:
"""Generate a given_name and surname for a passport owner
The ``gender`` argument is the gender marker of a passport owner, which is a one character string
that is either male, female, or non-binary.
Expand Down
6 changes: 4 additions & 2 deletions faker/providers/passport/en_US/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import date, timedelta
from typing import Tuple

from faker.typing import SexLiteral

from .. import Provider as PassportProvider


Expand Down Expand Up @@ -64,7 +66,7 @@ def passport_dates(self, birthday: date = date.today()) -> Tuple[str, str, str]:
expiry_date_format = expiry_date.strftime("%d ") + expiry_date.strftime("%b ") + expiry_date.strftime("%Y")
return birth_date, issue_date_format, expiry_date_format

def passport_gender(self, seed: int = 0) -> str:
def passport_gender(self, seed: int = 0) -> SexLiteral:
"""Generates a string representing the gender displayed on a passport
Sources:
Expand All @@ -75,7 +77,7 @@ def passport_gender(self, seed: int = 0) -> str:
random.seed(seed)

genders = ["M", "F", "X"]
gender = random.choices(genders, weights=[0.493, 0.493, 0.014], k=1)[0]
gender: SexLiteral = random.choices(genders, weights=[0.493, 0.493, 0.014], k=1)[0] # type: ignore
return gender

def passport_full(self) -> str:
Expand Down
12 changes: 6 additions & 6 deletions faker/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ class Faker:
"""
...

def passport_gender(self, seed: int = ...) -> str:
def passport_gender(self, seed: int = ...) -> Literal["M", "F", "X"]:
"""
Generates a string representing the gender displayed on a passport
Expand All @@ -2384,7 +2384,7 @@ class Faker:
"""
...

def passport_owner(self, gender: str = ...) -> Tuple[str, str]:
def passport_owner(self, gender: Literal["M", "F", "X"] = ...) -> Tuple[str, str]:
"""
Generate a given_name and surname for a passport owner
The ``gender`` argument is the gender marker of a passport owner, which is a one character string
Expand Down Expand Up @@ -2433,7 +2433,7 @@ class Faker:

def phone_number(self) -> str: ...
def profile(
self, fields: Optional[List[str]] = ..., sex: Optional[Literal["M", "F"]] = ...
self, fields: Optional[List[str]] = ..., sex: Optional[Literal["M", "F", "X"]] = ...
) -> Dict[str, Union[str, Tuple[Decimal, Decimal], List[str], datetime.date]]:
"""
Generates a complete profile.
Expand All @@ -2442,8 +2442,8 @@ class Faker:
...

def simple_profile(
self, sex: Optional[Literal["M", "F"]] = ...
) -> Dict[str, Union[str, datetime.date, Literal["M", "F"]]]:
self, sex: Optional[Literal["M", "F", "X"]] = ...
) -> Dict[str, Union[str, datetime.date, Literal["M", "F", "X"]]]:
"""
Generates a basic profile with personal informations
"""
Expand Down Expand Up @@ -4182,7 +4182,7 @@ class Faker:
"""
...

def full_name(self, gender: Optional[Literal["M", "F"]] = ..., short: Optional[bool] = ...) -> str:
def full_name(self, gender: Optional[Literal["M", "F", "X"]] = ..., short: Optional[bool] = ...) -> str:
"""
Generate Full Name
- gender = 'M' or 'F' optional params
Expand Down
2 changes: 1 addition & 1 deletion faker/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
CardType = TypeVar("CardType", "CreditCard", str)
DateParseType = Union[date, datetime, timedelta, str, int]
HueType = Union[str, float, int, Sequence[int]]
SexLiteral = Literal["M", "F"]
SexLiteral = Literal["M", "F", "X"]
SeedType = Union[int, float, str, bytes, bytearray, None]


Expand Down

0 comments on commit 2ccb85a

Please sign in to comment.