Conditions | 5 |
Total Lines | 76 |
Code Lines | 23 |
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 | # -*- coding: utf-8 -*- |
||
47 | def create_schedule( |
||
48 | self, |
||
49 | name: str, |
||
50 | icalendar: str, |
||
51 | timezone: str, |
||
52 | *, |
||
53 | comment: Optional[str] = None, |
||
54 | ) -> Any: |
||
55 | """Create a new schedule based in `iCalendar`_ data. |
||
56 | |||
57 | Example: |
||
58 | Requires https://pypi.org/project/icalendar/ |
||
59 | |||
60 | .. code-block:: python |
||
61 | |||
62 | import pytz |
||
63 | |||
64 | from datetime import datetime |
||
65 | |||
66 | from icalendar import Calendar, Event |
||
67 | |||
68 | cal = Calendar() |
||
69 | |||
70 | cal.add('prodid', '-//Foo Bar//') |
||
71 | cal.add('version', '2.0') |
||
72 | |||
73 | event = Event() |
||
74 | event.add('dtstamp', datetime.now(tz=pytz.UTC)) |
||
75 | event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc)) |
||
76 | |||
77 | cal.add_component(event) |
||
78 | |||
79 | gmp.create_schedule( |
||
80 | name="My Schedule", |
||
81 | icalendar=cal.to_ical(), |
||
82 | timezone='UTC' |
||
83 | ) |
||
84 | Arguments: |
||
85 | name: Name of the new schedule |
||
86 | icalendar: `iCalendar`_ (RFC 5545) based data. |
||
87 | timezone: Timezone to use for the icalender events e.g |
||
88 | Europe/Berlin. If the datetime values in the icalendar data are |
||
89 | missing timezone information this timezone gets applied. |
||
90 | Otherwise the datetime values from the icalendar data are |
||
91 | displayed in this timezone |
||
92 | comment: Comment on schedule. |
||
93 | |||
94 | Returns: |
||
95 | The response. See :py:meth:`send_command` for details. |
||
96 | |||
97 | .. _iCalendar: |
||
98 | https://tools.ietf.org/html/rfc5545 |
||
99 | """ |
||
100 | if not name: |
||
101 | raise RequiredArgument( |
||
102 | function=self.create_schedule.__name__, argument='name' |
||
103 | ) |
||
104 | if not icalendar: |
||
105 | raise RequiredArgument( |
||
106 | function=self.create_schedule.__name__, argument='icalendar' |
||
107 | ) |
||
108 | if not timezone: |
||
109 | raise RequiredArgument( |
||
110 | function=self.create_schedule.__name__, argument='timezone' |
||
111 | ) |
||
112 | |||
113 | cmd = XmlCommand("create_schedule") |
||
114 | |||
115 | cmd.add_element("name", name) |
||
116 | cmd.add_element("icalendar", icalendar) |
||
117 | cmd.add_element("timezone", timezone) |
||
118 | |||
119 | if comment: |
||
120 | cmd.add_element("comment", comment) |
||
121 | |||
122 | return self._send_xml_command(cmd) |
||
123 | |||
250 |