Conditions | 3 |
Total Lines | 52 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | """ |
||
41 | def parse(self, s: str) -> str: |
||
42 | today, now, now_utc = TyrannoInfo.today, TyrannoInfo.now, TyrannoInfo.now_utc |
||
43 | timestamp = TyrannoInfo.pretty_timestamp_with_offset |
||
44 | utc_stamp = TyrannoInfo.pretty_timestamp_utc |
||
45 | reps = { |
||
46 | "today": str(today), |
||
47 | "today.str": today.strftime("%Y-%m-%d"), |
||
48 | "today.year": str(today.year), |
||
49 | "today.month": str(today.month), |
||
50 | "today.Month": today.strftime("%B"), |
||
51 | "today.day": str(today.day), |
||
52 | "now": timestamp, |
||
53 | "now.utc": utc_stamp, |
||
54 | "now.iso": now.replace(microsecond=0).isoformat(), |
||
55 | "now.utciso": now_utc.replace(microsecond=0).isoformat(), |
||
56 | "now.hour": str(now.hour), |
||
57 | "now.minute": str(now.minute), |
||
58 | "now.second": str(now.second), |
||
59 | "project": self.project.lower(), |
||
60 | "Project": self.project.capitalize(), |
||
61 | "PROJECT": self.project.upper(), |
||
62 | "pkg": self.pkg, |
||
63 | "Pkg": self.pkg.title(), |
||
64 | "user": "<<TODO:user>>" if self.user is None else self.user, |
||
65 | "authors": self._pretty(self.authors), |
||
66 | "authors.list": self._list(self.authors), |
||
67 | "version": self.version, |
||
68 | "status.Name": self.status.name.capitalize(), |
||
69 | "status.name": self.status.name, |
||
70 | "status.pypi": self.status.pypi, |
||
71 | "status.dunder": self.status.dunder, |
||
72 | "status.Description": self.status.description.capitalize(), |
||
73 | "status.Description.": self._sentence(self.status.description), |
||
74 | "status.description": self.status.description, |
||
75 | "Description": self.description.capitalize(), |
||
76 | "description": self.description, |
||
77 | "Description.": self._sentence(self.description), |
||
78 | "keywords": self._pretty(self.keywords), |
||
79 | "keywords.list": self._list(self.keywords), |
||
80 | "license": self.license.name, |
||
81 | "license.name": self.license.full_name, |
||
82 | "license.spdx": self.license.spdx, |
||
83 | "license.official": self.license.spdx, |
||
84 | "license.family": self.license.family, |
||
85 | "license.header": self.download_license_template(header=True), |
||
86 | "license.full": self.download_license_template(header=False), |
||
87 | "license.url": self.license.url, |
||
88 | "tyranno.version": self.tyranno_vr, |
||
89 | } |
||
90 | for k, v in reps.items(): |
||
91 | s = s.replace("$${" + k + "}", v) |
||
92 | return s |
||
93 | |||
117 |