Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop creating attributes outside of __init__ #146

Merged
merged 2 commits into from
May 11, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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