Skip to content

Commit

Permalink
fix tpying
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Oct 15, 2024
1 parent 8cee450 commit 2495705
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions faker/providers/misc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Type, Union

from typing_extensions import TypeAlias

from faker.exceptions import UnsupportedFeature

from .. import BaseProvider
Expand All @@ -21,6 +23,10 @@
csv.register_dialect("faker-csv", csv.excel, quoting=csv.QUOTE_ALL)


ColumnSpec: TypeAlias = Union[Tuple[int, str], Tuple[int, str, Dict[str, Any]]]
DataColumns: TypeAlias = List[ColumnSpec]


class Provider(BaseProvider):
def boolean(self, chance_of_getting_true: int = 50) -> bool:
"""Generate a random boolean value based on ``chance_of_getting_true``.
Expand Down Expand Up @@ -643,7 +649,7 @@ def xml(
_dict = {self.generator.word(): _dict}
return xmltodict.unparse(_dict)

def fixed_width(self, data_columns: Optional[list] = None, num_rows: int = 10, align: str = "left") -> str:
def fixed_width(self, data_columns: Optional[DataColumns] = None, num_rows: int = 10, align: str = "left") -> str:
"""
Generate random fixed width values.
Expand Down Expand Up @@ -683,7 +689,8 @@ def fixed_width(self, data_columns: Optional[list] = None, num_rows: int = 10, a
(20, "name"),
(3, "pyint", {"max_value": 20}),
]
data_columns = data_columns if data_columns else default_data_columns
if data_columns is None:
data_columns: DataColumns = default_data_columns # type: ignore
align_map = {
"left": "<",
"middle": "^",
Expand All @@ -694,7 +701,7 @@ def fixed_width(self, data_columns: Optional[list] = None, num_rows: int = 10, a
for _ in range(num_rows):
row = []

for width, definition, *arguments in data_columns:
for width, definition, *arguments in data_columns: # type: ignore
kwargs = arguments[0] if arguments else {}

if not isinstance(kwargs, dict):
Expand Down
7 changes: 6 additions & 1 deletion faker/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,12 @@ class Faker:
"""
...

def fixed_width(self, data_columns: Optional[list] = ..., num_rows: int = ..., align: str = ...) -> str:
def fixed_width(
self,
data_columns: Optional[List[Union[Tuple[int, str], Tuple[int, str, Dict[str, Any]]]]] = ...,
num_rows: int = ...,
align: str = ...,
) -> str:
"""
Generate random fixed width values.
Expand Down

0 comments on commit 2495705

Please sign in to comment.