Skip to content

Commit

Permalink
Merge pull request #146 from n1analytics/fix-make-attrs-outside-init
Browse files Browse the repository at this point in the history
Stop creating attributes outside of __init__
  • Loading branch information
nbgl authored May 11, 2018
2 parents f6cd281 + 0afd284 commit 04f489e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion clkhash/randomnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import pkgutil
import random
import re
from typing import Dict, Iterable, List, Sequence, TextIO, Tuple, Union
from typing import (Dict, Iterable, List, Optional,
Sequence, TextIO, Tuple, Union)

from future.builtins import range

Expand Down Expand Up @@ -94,6 +95,10 @@ def __init__(self, n):

self.names = [person for person in self.generate_random_person(n)]

self.all_male_first_names = None # type: Optional[Sequence[str]]
self.all_female_first_names = None # type: Optional[Sequence[str]]
self.all_last_names = None # type: Optional[Sequence[str]]

@property
def schema_types(self):
# type: () -> Sequence[FieldSpec]
Expand All @@ -107,6 +112,9 @@ def generate_random_person(self, n):
:yields: Generated data for one person
tuple - (id: int, name: str('First Last'), birthdate: str('DD/MM/YYYY'), sex: str('M' | 'F') )
"""
assert self.all_male_first_names is not None
assert self.all_female_first_names is not None
assert self.all_last_names is not None
for i in range(n):
sex = 'M' if random.random() > 0.5 else 'F'
dob = random_date(self.earliest_birthday, self.latest_birthday).strftime("%Y/%m/%d")
Expand Down

0 comments on commit 04f489e

Please sign in to comment.