Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class gen_doc_google:
- '''
- Obiekt generujący doc string na podstawie norm stylizacji google
- Args:
- dictionary: (dict) słownik zapewniający informacje do stworzenia doc stringa
- Attributes:
- dictionary: tu przechowujemy informacje o parametrze dictionary
- '''
- def __init__(self, dictionary):
- self.dictionary = dictionary
- def __str__(self):
- """
- Funkcja specjalna zamienia zbudowaną liste na stringa i konwertująca obiekt gen_doc_google na stringa
- """
- return "".join(self.build())
- def __repr__(self):
- """
- Funkcja specjalna zamienia zbudowaną liste na stringa i konwertująca obiekt gen_doc_google na stringa
- """
- return "".join(self.build())
- def build(self):
- """
- Metoda budująca liste informacji potrzebnych do stworzenia doc stringa.
- Returns:
- list,
- """
- doc = ['"""\n']
- for key in self.dictionary:
- doc.append('\t{0}: \n'.format(key))
- if key == "Args":
- for info in self.dictionary[key]:
- doc.append("\t\t\t {0}: ({1})\n".format(info, self.dictionary[key][info].__name__))
- if key == "Attributes":
- for info in self.dictionary[key]:
- doc.append("\t\t\t {0}: tu przechowujemy informacje o parametrze {1}\n".format(info, info))
- if key == "Raises":
- for info in self.dictionary[key]:
- doc.append("\t\t\t {0}, \n".format(info.__name__))
- if key == "Returns":
- for info in self.dictionary[key]:
- doc.append("\t\t\t {0}, \n".format(info.__name__))
- if key == "Summary":
- del doc[-1]
- doc.insert(1, "\t" + self.dictionary[key] + "\n\n")
- if key == "Description":
- del doc[-1]
- doc.insert(2, "\t" + self.dictionary[key] + "\n\n")
- doc.append('\n"""')
- return doc
- print(gen_doc_google({'Args': {'a':str, 'b':int},
- 'Attributes': ['a', 'b'],
- 'Summary': "Obiekt Gruszka opisuje nam wlasnosci gruszek.",
- 'Returns': [bool],
- 'Raises': [AttributeError, ValueError, TypeError],
- 'Description': "Bardziej dokładny opis gruszki chyba"}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement