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

Added type hinting and function annotation. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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: 5 additions & 5 deletions names/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from os.path import abspath, join, dirname
import random

from typing import Optional

__title__ = 'names'
__version__ = '0.3.0.post1'
Expand All @@ -19,7 +19,7 @@
}


def get_name(filename):
def get_name(filename) -> str:
selected = random.random() * 90
with open(filename) as name_file:
for line in name_file:
Expand All @@ -29,17 +29,17 @@ def get_name(filename):
return "" # Return empty string if file is empty


def get_first_name(gender=None):
def get_first_name(gender: Optional[str] = None) -> str:
if gender is None:
gender = random.choice(('male', 'female'))
if gender not in ('male', 'female'):
raise ValueError("Only 'male' and 'female' are supported as gender")
return get_name(FILES['first:%s' % gender]).capitalize()


def get_last_name():
def get_last_name() -> str:
return get_name(FILES['last']).capitalize()


def get_full_name(gender=None):
def get_full_name(gender: Optional[str] = None) -> str:
return "{0} {1}".format(get_first_name(gender), get_last_name())