Skip to content

Commit

Permalink
Rename word_list argument to words() back to ext_word_list
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Jun 26, 2024
1 parent b01507a commit fb8b8a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions faker/providers/lorem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def get_words_list(
else:
word_list = self.word_list # type: ignore[attr-defined]

return word_list
return list(word_list)

def words(
self,
nb: int = 3,
word_list: List[str] = None,
ext_word_list: Optional[List[str]] = None,
unique: bool = False,
) -> List[str]:
"""Generate a tuple of words.
Expand All @@ -89,8 +89,10 @@ def words(
:sample: nb=4, ext_word_list=['abc', 'def', 'ghi', 'jkl'], unique=True
"""

if word_list is None:
if ext_word_list is None:
word_list = self.get_words_list()
else:
word_list = ext_word_list

if unique:
unique_samples = cast(List[str], self.random_sample(word_list, length=nb))
Expand Down Expand Up @@ -137,7 +139,7 @@ def sentence(
nb_words = self.randomize_nb_elements(nb_words, min=1)

word_list = self.get_words_list(ext_word_list=ext_word_list)
words = list(self.words(nb=nb_words, word_list=word_list))
words = list(self.words(nb=nb_words, ext_word_list=word_list))
words[0] = words[0].title()

return self.word_connector.join(words) + self.sentence_punctuation
Expand Down
2 changes: 1 addition & 1 deletion faker/providers/lorem/en_PH/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def english_words(self, nb: int = 3, unique: bool = False) -> List[str]:

word_list = self.generator.get_words_list(ext_word_list=self.english_word_list)

return self.words(nb=nb, word_list=word_list, unique=unique)
return self.words(nb=nb, ext_word_list=word_list, unique=unique)

def english_sentence(self, nb_words: int = 6, variable_nb_words: bool = True) -> str:
"""Generate a sentence in English.
Expand Down
2 changes: 1 addition & 1 deletion faker/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ class Faker:
:sample: ext_word_list=['abc', 'def', 'ghi', 'jkl']
"""
...
def words(self, nb: int = ..., word_list: List[str] = ..., unique: bool = ...) -> List[str]:
def words(self, nb: int = ..., ext_word_list: Optional[List[str]] = ..., unique: bool = ...) -> List[str]:
"""
Generate a tuple of words.
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/test_lorem.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def test_words_with_defaults(self, faker, num_samples):
def test_words_with_custom_word_list(self, faker, num_samples):
num_words = 5
for _ in range(num_samples):
words = faker.words(num_words, word_list=self.custom_word_list)
words = faker.words(num_words, ext_word_list=self.custom_word_list)
assert isinstance(words, list)
assert len(words) == 5
assert all(isinstance(word, str) and word in self.custom_word_list for word in words)

def test_words_with_unique_sampling(self, faker, num_samples):
num_words = 5
for _ in range(num_samples):
words = faker.words(num_words, word_list=self.custom_word_list, unique=True)
words = faker.words(num_words, ext_word_list=self.custom_word_list, unique=True)
assert isinstance(words, list)
assert len(words) == 5

Expand Down

0 comments on commit fb8b8a2

Please sign in to comment.