Skip to content

Commit

Permalink
DOC add docstring under random_varname, all_subclasses functions (#129)
Browse files Browse the repository at this point in the history
Contributes to #105
  • Loading branch information
lfunderburk authored May 24, 2021
1 parent 5abc4c2 commit 08b57af
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions testbook/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@


def random_varname(length=10):
"""
Creates a random variable name as string of a given length.
This is used in testbook to generate temporary variables within the notebook.
Parameters
----------
length (int)
Returns:
--------
random variable name as string of given length
"""
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))


def all_subclasses(klass):
"""
This is a function that returns a generator.
Inspects subclasses associated with a given class in a recursive manner
and yields them, such that subclasses of subclasses will be yielded.
Parameters:
-----------
klass
"""
for subklass in klass.__subclasses__():
yield subklass
yield from all_subclasses(subklass)

0 comments on commit 08b57af

Please sign in to comment.