From 6054e65916c3d418d450b74fc6d1b230ae22eae6 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:32:17 +0500 Subject: [PATCH 01/22] docs: convert docstrings to Google style in parser_tools and component (#1072) --- src/icalendar/cal/component.py | 76 +++++++++++++++++----------------- src/icalendar/parser_tools.py | 13 ++++-- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 41f5f5a3c..bb247592a 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -137,7 +137,7 @@ def _get_component_factory(cls) -> ComponentFactory: def get_component_class(cls, name: str) -> type[Component]: """Return a component with this name. - Parameters: + Args: name: Name of the component, i.e. ``VCALENDAR`` """ return cls._get_component_factory().get_component_class(name) @@ -146,7 +146,7 @@ def get_component_class(cls, name: str) -> type[Component]: def register(cls, component_class: type[Component]) -> None: """Register a custom component class. - Parameters: + Args: component_class: Component subclass to register. Must have a ``name`` attribute. @@ -186,7 +186,7 @@ def _infer_value_type( ) -> str | None: """Infer the ``VALUE`` parameter from a Python type. - Parameters: + Args: value: Python native type, one of :class:`datetime.date`, :class:`datetime.datetime`, :class:`datetime.timedelta`, :class:`datetime.time`, :class:`tuple`, or :class:`list`. @@ -247,26 +247,21 @@ def is_empty(self) -> bool: # handling of property values @classmethod - def _encode(cls, name, value, parameters=None, encode=1): + def _encode(cls, name: str, value: Any, parameters: dict[str, str] | Parameters | None = None, encode: bool = True) -> Any: """Encode values to icalendar property values. - :param name: Name of the property. - :type name: string - - :param value: Value of the property. Either of a basic Python type of - any of the icalendar's own property types. - :type value: Python native type or icalendar property type. - - :param parameters: Property parameter dictionary for the value. Only - available, if encode is set to True. - :type parameters: Dictionary - - :param encode: True, if the value should be encoded to one of - icalendar's own property types (Fallback is "vText") - or False, if not. - :type encode: Boolean + Args: + name: Name of the property. + value: Value of the property. Either of a basic Python type of + any of the icalendar's own property types. + parameters: Property parameter dictionary for the value. Only + available, if encode is set to True. + encode: True, if the value should be encoded to one of + icalendar's own property types (Fallback is "vText") + or False, if not. - :returns: icalendar property value + Returns: + icalendar property value """ if not encode: return value @@ -316,7 +311,7 @@ def add( and ``value`` is a ``datetime``, the value is converted to UTC as the RFC requires. - Parameters: + Args: name: Name of the property. value: Value of the property. Either a basic Python type or any of @@ -457,11 +452,13 @@ def walk( """Recursively traverses component and subcomponents. Returns sequence of same. If name is passed, only components with name will be returned. - :param name: The name of the component or None such as ``VEVENT``. - :param select: A function that takes the component as first argument - and returns True/False. - :returns: A list of components that match. - :rtype: list[Component] + Args: + name: The name of the component or None such as ``VEVENT``. + select: A function that takes the component as first argument + and returns True/False. + + Returns: + A list of components that match. """ if name is not None: name = name.upper() @@ -470,7 +467,7 @@ def walk( def with_uid(self, uid: str) -> list[Component]: """Return a list of components with the given UID. - Parameters: + Args: uid: The UID of the component. Returns: @@ -547,7 +544,7 @@ def from_ical( Handles standard and custom components (``X-*``, IANA-registered). - Parameters: + Args: st: iCalendar data as bytes or string, or a path to an iCalendar file as :class:`pathlib.Path` or string. multiple: If ``True``, returns list. If ``False``, returns single component. @@ -617,10 +614,15 @@ def content_lines(self, sorted: bool = True): contentlines.append("") # remember the empty string in the end return contentlines - def to_ical(self, sorted: bool = True): - """ - :param sorted: Whether parameters and properties should be - lexicographically sorted. + def to_ical(self, sorted: bool = True) -> bytes: + """Convert component to iCalendar format. + + Args: + sorted: Whether parameters and properties should be + lexicographically sorted. + + Returns: + The iCalendar representation of the component. """ content_lines = self.content_lines(sorted=sorted) @@ -888,7 +890,7 @@ def new( ) -> Self: """Create a new component. - Parameters: + Args: comments: The :attr:`comments` of the component. concepts: The :attr:`concepts` of the component. created: The :attr:`created` of the component. @@ -983,7 +985,7 @@ def to_json(self) -> str: def from_jcal(cls, jcal: str | list) -> Component: """Create a component from a jCal list. - Parameters: + Args: jcal: jCal list or JSON string according to :rfc:`7265`. Raises: @@ -1052,7 +1054,7 @@ def from_jcal(cls, jcal: str | list) -> Component: def copy(self, recursive: bool = False) -> Self: """Copy the component. - Parameters: + Args: recursive: If ``True``, this creates copies of the component, its subcomponents, and all its properties. @@ -1115,14 +1117,14 @@ def parse(self) -> Self: return self -def _node_from_jcal(jcal, starting_cls: type[Component]) -> tuple[Component, list]: +def _node_from_jcal(jcal: list, starting_cls: type[Component]) -> tuple[Component, list]: """Parse a single jCal component without recursing into subcomponents. Module-level helper for :meth:`Component.from_jcal`: it has no ties to a class or instance (the relevant class is passed in as ``starting_cls``), so it is a plain function rather than a (static) method. - Parameters: + Args: jcal: The jCal list for one component. starting_cls: The class used as the parser for structural validation before the component type is resolved from its name (the entry diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index ef702970e..5ff930833 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -6,7 +6,7 @@ def from_unicode(value: ICAL_TYPE, encoding: str = "utf-8") -> bytes: """Converts a value to bytes, even if it is already bytes. - Parameters: + Args: value: The value to convert. encoding: The encoding to use in the conversion. @@ -27,9 +27,12 @@ def from_unicode(value: ICAL_TYPE, encoding: str = "utf-8") -> bytes: def to_unicode(value: ICAL_TYPE, encoding: str = "utf-8-sig") -> str: """Converts a value to Unicode, even if it is already a Unicode string. - Parameters: + Args: value: The value to convert. encoding: The encoding to use in the conversion. + + Returns: + The Unicode string representation of the value. """ if isinstance(value, str): return value @@ -49,8 +52,12 @@ def data_encode( Currently Unicode strings, dicts, and lists are supported. - Parameters: + Args: data: The datastructure to encode. + encoding: The encoding to use in the conversion. + + Returns: + The encoded datastructure. """ # https://stackoverflow.com/questions/1254454/fastest-way-to-convert-a-dicts-keys-values-from-unicode-to-str if isinstance(data, str): From 76f2f5deee808708ba0c5f5b9af8e1ad3365abc7 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:44:24 +0500 Subject: [PATCH 02/22] docs: add changelog entry for #1072 (#1749) --- docs/1749.doc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/1749.doc.rst diff --git a/docs/1749.doc.rst b/docs/1749.doc.rst new file mode 100644 index 000000000..1fe7776cd --- /dev/null +++ b/docs/1749.doc.rst @@ -0,0 +1 @@ +Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. (#1072) From f97f8b48096d9a557210af39b30286cba6a0d8d7 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:46:56 +0500 Subject: [PATCH 03/22] chore: move news fragment to docs/changelog/1749.doc.rst --- docs/{ => changelog}/1749.doc.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{ => changelog}/1749.doc.rst (100%) diff --git a/docs/1749.doc.rst b/docs/changelog/1749.doc.rst similarity index 100% rename from docs/1749.doc.rst rename to docs/changelog/1749.doc.rst From 477436b90f8f7e2ef4de5c3ffd65bf647078512b Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:48:06 +0500 Subject: [PATCH 04/22] chore: move news fragment to docs/changelog/1749.doc.rst (#1749) --- docs/changelog/1749.doc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/1749.doc.rst b/docs/changelog/1749.doc.rst index 1fe7776cd..648ec22c3 100644 --- a/docs/changelog/1749.doc.rst +++ b/docs/changelog/1749.doc.rst @@ -1 +1 @@ -Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. (#1072) +Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. From dc1c8b2212a4f0d95b45d7a5b8715ec7353c1a9e Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:48:59 +0500 Subject: [PATCH 05/22] docs: add news fragment 1749.doc.rst and 1072.doc.rst --- docs/1072.doc.rst | 1 + docs/1749.doc.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 docs/1072.doc.rst create mode 100644 docs/1749.doc.rst diff --git a/docs/1072.doc.rst b/docs/1072.doc.rst new file mode 100644 index 000000000..648ec22c3 --- /dev/null +++ b/docs/1072.doc.rst @@ -0,0 +1 @@ +Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. diff --git a/docs/1749.doc.rst b/docs/1749.doc.rst new file mode 100644 index 000000000..648ec22c3 --- /dev/null +++ b/docs/1749.doc.rst @@ -0,0 +1 @@ +Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. From 9d657db160b4a06d4f72d5fb4828013358a3d0db Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Wed, 2 Sep 2026 01:54:46 +0500 Subject: [PATCH 06/22] docs: add towncrier news fragment at news/1072.documentation.rst (#1749) --- docs/1749.doc.rst | 1 - docs/changelog/1749.doc.rst | 1 - docs/1072.doc.rst => news/1072.documentation.rst | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 docs/1749.doc.rst delete mode 100644 docs/changelog/1749.doc.rst rename docs/1072.doc.rst => news/1072.documentation.rst (74%) diff --git a/docs/1749.doc.rst b/docs/1749.doc.rst deleted file mode 100644 index 648ec22c3..000000000 --- a/docs/1749.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. diff --git a/docs/changelog/1749.doc.rst b/docs/changelog/1749.doc.rst deleted file mode 100644 index 648ec22c3..000000000 --- a/docs/changelog/1749.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. diff --git a/docs/1072.doc.rst b/news/1072.documentation.rst similarity index 74% rename from docs/1072.doc.rst rename to news/1072.documentation.rst index 648ec22c3..8eba6e898 100644 --- a/docs/1072.doc.rst +++ b/news/1072.documentation.rst @@ -1 +1 @@ -Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. +Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. (#1072) \ No newline at end of file From b3d3465c0f57d61cea0d4744c0a967ac5f6fb07a Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Fri, 4 Sep 2026 15:38:01 +0500 Subject: [PATCH 07/22] docs: revert Args to Parameters per style guide and format with ruff --- src/icalendar/cal/component.py | 38 ++++++++++++++++++++-------------- src/icalendar/parser_tools.py | 6 +++--- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index bb247592a..8a9ab3e3d 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -137,7 +137,7 @@ def _get_component_factory(cls) -> ComponentFactory: def get_component_class(cls, name: str) -> type[Component]: """Return a component with this name. - Args: + Parameters: name: Name of the component, i.e. ``VCALENDAR`` """ return cls._get_component_factory().get_component_class(name) @@ -146,7 +146,7 @@ def get_component_class(cls, name: str) -> type[Component]: def register(cls, component_class: type[Component]) -> None: """Register a custom component class. - Args: + Parameters: component_class: Component subclass to register. Must have a ``name`` attribute. @@ -186,7 +186,7 @@ def _infer_value_type( ) -> str | None: """Infer the ``VALUE`` parameter from a Python type. - Args: + Parameters: value: Python native type, one of :class:`datetime.date`, :class:`datetime.datetime`, :class:`datetime.timedelta`, :class:`datetime.time`, :class:`tuple`, or :class:`list`. @@ -247,10 +247,16 @@ def is_empty(self) -> bool: # handling of property values @classmethod - def _encode(cls, name: str, value: Any, parameters: dict[str, str] | Parameters | None = None, encode: bool = True) -> Any: + def _encode( + cls, + name: str, + value: Any, + parameters: dict[str, str] | Parameters | None = None, + encode: bool = True, + ) -> Any: """Encode values to icalendar property values. - Args: + Parameters: name: Name of the property. value: Value of the property. Either of a basic Python type of any of the icalendar's own property types. @@ -311,7 +317,7 @@ def add( and ``value`` is a ``datetime``, the value is converted to UTC as the RFC requires. - Args: + Parameters: name: Name of the property. value: Value of the property. Either a basic Python type or any of @@ -452,7 +458,7 @@ def walk( """Recursively traverses component and subcomponents. Returns sequence of same. If name is passed, only components with name will be returned. - Args: + Parameters: name: The name of the component or None such as ``VEVENT``. select: A function that takes the component as first argument and returns True/False. @@ -467,7 +473,7 @@ def walk( def with_uid(self, uid: str) -> list[Component]: """Return a list of components with the given UID. - Args: + Parameters: uid: The UID of the component. Returns: @@ -544,7 +550,7 @@ def from_ical( Handles standard and custom components (``X-*``, IANA-registered). - Args: + Parameters: st: iCalendar data as bytes or string, or a path to an iCalendar file as :class:`pathlib.Path` or string. multiple: If ``True``, returns list. If ``False``, returns single component. @@ -617,7 +623,7 @@ def content_lines(self, sorted: bool = True): def to_ical(self, sorted: bool = True) -> bytes: """Convert component to iCalendar format. - Args: + Parameters: sorted: Whether parameters and properties should be lexicographically sorted. @@ -890,7 +896,7 @@ def new( ) -> Self: """Create a new component. - Args: + Parameters: comments: The :attr:`comments` of the component. concepts: The :attr:`concepts` of the component. created: The :attr:`created` of the component. @@ -985,7 +991,7 @@ def to_json(self) -> str: def from_jcal(cls, jcal: str | list) -> Component: """Create a component from a jCal list. - Args: + Parameters: jcal: jCal list or JSON string according to :rfc:`7265`. Raises: @@ -1054,7 +1060,7 @@ def from_jcal(cls, jcal: str | list) -> Component: def copy(self, recursive: bool = False) -> Self: """Copy the component. - Args: + Parameters: recursive: If ``True``, this creates copies of the component, its subcomponents, and all its properties. @@ -1117,14 +1123,16 @@ def parse(self) -> Self: return self -def _node_from_jcal(jcal: list, starting_cls: type[Component]) -> tuple[Component, list]: +def _node_from_jcal( + jcal: list, starting_cls: type[Component] +) -> tuple[Component, list]: """Parse a single jCal component without recursing into subcomponents. Module-level helper for :meth:`Component.from_jcal`: it has no ties to a class or instance (the relevant class is passed in as ``starting_cls``), so it is a plain function rather than a (static) method. - Args: + Parameters: jcal: The jCal list for one component. starting_cls: The class used as the parser for structural validation before the component type is resolved from its name (the entry diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index 5ff930833..539d182d2 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -6,7 +6,7 @@ def from_unicode(value: ICAL_TYPE, encoding: str = "utf-8") -> bytes: """Converts a value to bytes, even if it is already bytes. - Args: + Parameters: value: The value to convert. encoding: The encoding to use in the conversion. @@ -27,7 +27,7 @@ def from_unicode(value: ICAL_TYPE, encoding: str = "utf-8") -> bytes: def to_unicode(value: ICAL_TYPE, encoding: str = "utf-8-sig") -> str: """Converts a value to Unicode, even if it is already a Unicode string. - Args: + Parameters: value: The value to convert. encoding: The encoding to use in the conversion. @@ -52,7 +52,7 @@ def data_encode( Currently Unicode strings, dicts, and lists are supported. - Args: + Parameters: data: The datastructure to encode. encoding: The encoding to use in the conversion. From f77ddbdeb64e426c7d2fa26348cce2898c22cbde Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:11:10 +0500 Subject: [PATCH 08/22] docs: rename news fragment to PR 1749 --- news/{1072.documentation.rst => 1749.documentation.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename news/{1072.documentation.rst => 1749.documentation.rst} (100%) diff --git a/news/1072.documentation.rst b/news/1749.documentation.rst similarity index 100% rename from news/1072.documentation.rst rename to news/1749.documentation.rst From c19c3da5fe0f71f2c423da7ce903a8076421c6b7 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:14:28 +0500 Subject: [PATCH 09/22] Apply suggestion from @stevepiercy Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 8a9ab3e3d..33f9c1574 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -262,9 +262,9 @@ def _encode( any of the icalendar's own property types. parameters: Property parameter dictionary for the value. Only available, if encode is set to True. - encode: True, if the value should be encoded to one of - icalendar's own property types (Fallback is "vText") - or False, if not. + encode: ``True`` if the value should be encoded to one of + icalendar's own property types with a fallback to + :attr:`~icalendar.prop.text.vText`, else ``False``. Returns: icalendar property value From 7f0a9f67ff92f022135b2624daa827e296889d86 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:16:13 +0500 Subject: [PATCH 10/22] Update src/icalendar/parser_tools.py Co-authored-by: Steve Piercy --- src/icalendar/parser_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index 539d182d2..c63f302cc 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -48,7 +48,7 @@ def to_unicode(value: ICAL_TYPE, encoding: str = "utf-8-sig") -> str: def data_encode( data: ICAL_TYPE | dict | list, encoding: str = DEFAULT_ENCODING ) -> bytes | list[bytes] | dict: - """Encode all datastructures to the given encoding. + """Encode all data structures to the given encoding. Currently Unicode strings, dicts, and lists are supported. From 08393c1ff41cfbaabc52ae4ed1a4b0657cf58f5a Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:16:22 +0500 Subject: [PATCH 11/22] Update src/icalendar/parser_tools.py Co-authored-by: Steve Piercy --- src/icalendar/parser_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index c63f302cc..8688ec475 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -53,7 +53,7 @@ def data_encode( Currently Unicode strings, dicts, and lists are supported. Parameters: - data: The datastructure to encode. + data: The data structure to encode. encoding: The encoding to use in the conversion. Returns: From 4aa83545eab213188964a3e242b876d2e7d8a5d0 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:16:33 +0500 Subject: [PATCH 12/22] Update src/icalendar/parser_tools.py Co-authored-by: Steve Piercy --- src/icalendar/parser_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index 8688ec475..a81b1e22b 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -57,7 +57,7 @@ def data_encode( encoding: The encoding to use in the conversion. Returns: - The encoded datastructure. + The encoded data structure. """ # https://stackoverflow.com/questions/1254454/fastest-way-to-convert-a-dicts-keys-values-from-unicode-to-str if isinstance(data, str): From fcdc71f1d5904aafbda99013089ce12d9c560a5c Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:16:43 +0500 Subject: [PATCH 13/22] Update src/icalendar/cal/component.py Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 33f9c1574..28a924a18 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -460,8 +460,8 @@ def walk( Parameters: name: The name of the component or None such as ``VEVENT``. - select: A function that takes the component as first argument - and returns True/False. + select: A function that takes the component as its first argument + and returns either ``True`` or ``False``. Returns: A list of components that match. From 0648b968a2928d8decff58595d7375bfb8d10354 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:16:58 +0500 Subject: [PATCH 14/22] Update src/icalendar/cal/component.py Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 28a924a18..3e50e8591 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -459,7 +459,7 @@ def walk( of same. If name is passed, only components with name will be returned. Parameters: - name: The name of the component or None such as ``VEVENT``. + name: The name of the component, such as ``VEVENT``, or ``None``. select: A function that takes the component as its first argument and returns either ``True`` or ``False``. From e76e22235308d85f026991bfa56285950ea81f85 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:17:08 +0500 Subject: [PATCH 15/22] Update src/icalendar/cal/component.py Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 3e50e8591..14b8cab5d 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -266,6 +266,7 @@ def _encode( icalendar's own property types with a fallback to :attr:`~icalendar.prop.text.vText`, else ``False``. + Returns: icalendar property value """ From e14407943a7b42c0e9ca95ad4cb662b36f2fa3df Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:17:25 +0500 Subject: [PATCH 16/22] Update src/icalendar/cal/component.py Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 14b8cab5d..c1af26e35 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -261,7 +261,7 @@ def _encode( value: Value of the property. Either of a basic Python type of any of the icalendar's own property types. parameters: Property parameter dictionary for the value. Only - available, if encode is set to True. + available if ``encode`` is set to ``True``. encode: ``True`` if the value should be encoded to one of icalendar's own property types with a fallback to :attr:`~icalendar.prop.text.vText`, else ``False``. From f25b927c0995542177f2bfd5d844106b41df305a Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:17:35 +0500 Subject: [PATCH 17/22] Update src/icalendar/cal/component.py Co-authored-by: Steve Piercy --- src/icalendar/cal/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index c1af26e35..31b949966 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -258,8 +258,8 @@ def _encode( Parameters: name: Name of the property. - value: Value of the property. Either of a basic Python type of - any of the icalendar's own property types. + value: Value of the property. Either a basic Python type or + any of icalendar's own property types. parameters: Property parameter dictionary for the value. Only available if ``encode`` is set to ``True``. encode: ``True`` if the value should be encoded to one of From 863d3890ea8236ec3c103ec2116524015d28a610 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Mon, 7 Sep 2026 00:29:34 +0500 Subject: [PATCH 18/22] typing: add type hints to Component.walk (#938, #1749) --- src/icalendar/cal/component.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 31b949966..19910f0c2 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -38,7 +38,7 @@ from icalendar.tools import is_date if TYPE_CHECKING: - from collections.abc import Iterable + from collections.abc import Callable, Iterable from icalendar.compatibility import Self @@ -439,7 +439,7 @@ def add_component(self, component: Component) -> None: self.subcomponents.append(component) def _walk( - self, name: str | None, select: callable[[Component], bool] + self, name: str | None, select: Callable[[Component], bool] ) -> list[Component]: """Walk to given component.""" result = [] @@ -451,13 +451,19 @@ def _walk( stack.extend(reversed(component.subcomponents)) return result + @staticmethod + def __identity(_component: Component) -> bool: + """Identity selector for :meth:`Component.walk`.""" + return True + def walk( self, name: str | None = None, - select: callable[[Component], bool] = lambda _: True, + select: Callable[[Component], bool] = __identity, ) -> list[Component]: - """Recursively traverses component and subcomponents. Returns sequence - of same. If name is passed, only components with name will be returned. + """Recursively traverses component and subcomponents and returns a + sequence of them. If name is passed, only components with that name + will be returned. Parameters: name: The name of the component, such as ``VEVENT``, or ``None``. From 253c9f6801e8d4114fbedf832e7997868600b635 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Date: Thu, 10 Sep 2026 23:42:29 +0500 Subject: [PATCH 19/22] docs: address remaining docstring review feedback and update changelog entry --- news/1749.documentation.rst | 2 +- src/icalendar/cal/component.py | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/news/1749.documentation.rst b/news/1749.documentation.rst index 8eba6e898..10470d0a7 100644 --- a/news/1749.documentation.rst +++ b/news/1749.documentation.rst @@ -1 +1 @@ -Apply Google Style docstrings to ``parser_tools.py`` and ``cal/component.py``. (#1072) \ No newline at end of file +Converted docstrings in ``parser_tools.py`` and ``cal/component.py`` to Google Style. @AhmadBilalDSA \ No newline at end of file diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 19910f0c2..2963f35ff 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -138,7 +138,10 @@ def get_component_class(cls, name: str) -> type[Component]: """Return a component with this name. Parameters: - name: Name of the component, i.e. ``VCALENDAR`` + name: The name of the component, such as ``VCALENDAR``. + + Returns: + The component class registered for ``name``. """ return cls._get_component_factory().get_component_class(name) @@ -266,7 +269,6 @@ def _encode( icalendar's own property types with a fallback to :attr:`~icalendar.prop.text.vText`, else ``False``. - Returns: icalendar property value """ @@ -398,10 +400,18 @@ def _decode(self, name: str, value: VPROPERTY): return decoded def decoded(self, name: str, default: Any = _marker) -> Any: - """Returns decoded value of property. + """Return the decoded value of a property. A component maps keys to icalendar property value types. - This function returns values compatible to native Python types. + This function returns values compatible with native Python types. + + Parameters: + name: The name of the property. + default: The value to return if the property is not present. + + Returns: + The decoded value of the property, or ``default`` if the + property is not present. """ if name in self: value = self[name] @@ -424,9 +434,7 @@ def get_inline(self, name, decode=1): return vals def set_inline(self, name, values, encode=1): - """Converts a list of values into comma separated string and sets value - to that. - """ + """Convert a list of values into a comma-separated string and set the property value to it.""" if encode: values = [self._encode(name, value, encode=1) for value in values] self[name] = self.types_factory["inline"](q_join(values)) @@ -461,9 +469,9 @@ def walk( name: str | None = None, select: Callable[[Component], bool] = __identity, ) -> list[Component]: - """Recursively traverses component and subcomponents and returns a - sequence of them. If name is passed, only components with that name - will be returned. + """Recursively traverse component and subcomponents and return a sequence of them. + + If ``name`` is passed, only components with that name will be returned. Parameters: name: The name of the component, such as ``VEVENT``, or ``None``. @@ -909,6 +917,7 @@ def new( created: The :attr:`created` of the component. last_modified: The :attr:`last_modified` of the component. links: The :attr:`links` of the component. + refids: The :attr:`refids` of the component. related_to: The :attr:`related_to` of the component. stamp: The :attr:`DTSTAMP` of the component. subcomponents: The subcomponents of the component. From 0a02d22a60e1fd40356e331d239be480ffe49824 Mon Sep 17 00:00:00 2001 From: Jonas Eckert Date: Sun, 25 Oct 2026 07:44:44 +0100 Subject: [PATCH 20/22] Fix my parts of the PR --- src/icalendar/cal/component.py | 34 +++++++++++++++++++++++----------- src/icalendar/parser_tools.py | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 1a10b81e0..5f096d202 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -42,7 +42,7 @@ from icalendar.tools import is_date if TYPE_CHECKING: - from collections.abc import Callable, Iterable + from collections.abc import Callable, Iterable, Sequence from icalendar.compatibility import Self @@ -144,7 +144,7 @@ def get_component_class(cls, name: str) -> type[Component]: """Return a component with this name. Parameters: - name: The name of the component, such as ``VCALENDAR``. + name: Required. The name of the component, such as ``VCALENDAR``. Returns: The component class registered for ``name``. @@ -266,14 +266,14 @@ def _encode( """Encode values to icalendar property values. Parameters: - name: Name of the property. - value: Value of the property. Either a basic Python type or + name: Required. Name of the property. + value: Required. Value of the property. Either a basic Python type or any of icalendar's own property types. - parameters: Property parameter dictionary for the value. Only - available if ``encode`` is set to ``True``. encode: ``True`` if the value should be encoded to one of icalendar's own property types with a fallback to :attr:`~icalendar.prop.text.vText`, else ``False``. + parameters: Property parameter dictionary for the value. Only + available if ``encode`` is set to ``True``. Returns: icalendar property value @@ -412,8 +412,8 @@ def decoded(self, name: str, default: Any = _marker) -> Any: This function returns values compatible with native Python types. Parameters: - name: The name of the property. - default: The value to return if the property is not present. + default: Required. The value to return if the property is not present. + name: Required. The name of the property. Returns: The decoded value of the property, or ``default`` if the @@ -439,10 +439,22 @@ def get_inline(self, name, decode=1): return [self._decode(name, val) for val in vals] return vals - def set_inline(self, name, values, encode=1): - """Convert a list of values into a comma-separated string and set the property value to it.""" + def set_inline(self, name: str, values: Sequence[str], encode=1): + """Convert a list of values into a comma-separated string and set the + property value to it. + + Parameters: + name: Required. Name of the property. + values: Required. Values of the properties. The properties are + encoded, if ``encode`` is truthy. Then tey are joined to + form the fila property value. + encode: Has a truthy value if each value in values should be + encoded to one of icalendar's own property types with a + fallback to :attr:`~icalendar.prop.text.vText`, + else ``False``. + """ if encode: - values = [self._encode(name, value, encode=1) for value in values] + values = [self._encode(name, value, encode=True) for value in values] self[name] = self.types_factory["inline"](q_join(values)) ######################### diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index 440f08e02..d8599266b 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -57,7 +57,7 @@ def data_encode( Currently Unicode strings, dicts, and lists are supported. Parameters: - data: The data structure to encode. + data: Required. The data structure to encode. encoding: The encoding to use in the conversion. Returns: From fc136b58b2ef2519e04a33175e7e9c979f8d1169 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal <315737484+AhmadBilalDSA@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:43:39 +0500 Subject: [PATCH 21/22] docs: apply final docstring review feedback Prompt: Apply the remaining review suggestions for Component.walk signature rendering, the set_inline encode flag, default value notes, and the change log entry. Model: DeepSeek V4.1 Flash Free via opencode. Output: this commit. --- news/1749.documentation | 1 + news/1749.documentation.rst | 1 - src/icalendar/cal/component.py | 26 ++++++++++++++------------ src/icalendar/parser_tools.py | 3 ++- 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 news/1749.documentation delete mode 100644 news/1749.documentation.rst diff --git a/news/1749.documentation b/news/1749.documentation new file mode 100644 index 000000000..c8062a393 --- /dev/null +++ b/news/1749.documentation @@ -0,0 +1 @@ +Converted docstrings in :mod:`~icalendar.parser_tools.py` and :mod:`~icalendar.cal.component.py` to Google Style. I used AI to assist me with this change. @AhmadBilalDSA \ No newline at end of file diff --git a/news/1749.documentation.rst b/news/1749.documentation.rst deleted file mode 100644 index 10470d0a7..000000000 --- a/news/1749.documentation.rst +++ /dev/null @@ -1 +0,0 @@ -Converted docstrings in ``parser_tools.py`` and ``cal/component.py`` to Google Style. @AhmadBilalDSA \ No newline at end of file diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 8adfc0e24..2852fbb7e 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -310,6 +310,7 @@ def _encode( encode: ``True`` if the value should be encoded to one of icalendar's own property types with a fallback to :attr:`~icalendar.prop.text.vText`, else ``False``. + Default is ``True``. parameters: Property parameter dictionary for the value. Only available if ``encode`` is set to ``True``. @@ -375,7 +376,7 @@ def add( encode: ``True`` if the value should be encoded to one of icalendar's own property types (fallback is ``vText``); ``False`` to - store the value as-is. + store the value as-is. Default is ``True``. Returns: ``None`` @@ -477,19 +478,19 @@ def get_inline(self, name, decode=1): return [self._decode(name, val) for val in vals] return vals - def set_inline(self, name: str, values: Sequence[str], encode=1): + def set_inline(self, name: str, values: Sequence[str], encode: bool = True): """Convert a list of values into a comma-separated string and set the property value to it. Parameters: name: Required. Name of the property. values: Required. Values of the properties. The properties are - encoded, if ``encode`` is truthy. Then tey are joined to - form the fila property value. - encode: Has a truthy value if each value in values should be - encoded to one of icalendar's own property types with a - fallback to :attr:`~icalendar.prop.text.vText`, - else ``False``. + encoded, if ``encode`` is truthy. Then they are joined to + form the property value. + encode: ``True`` if each value in values should be encoded to one + of icalendar's own property types with a fallback to + :attr:`~icalendar.prop.text.vText`, else ``False``. + Default is ``True``. """ if encode: values = [self._encode(name, value, encode=True) for value in values] @@ -523,7 +524,7 @@ def __identity(_component: Component) -> bool: def walk( self, name: str | None = None, - select: Callable[[Component], bool] = __identity, + select: Callable[[Component], bool] | None = None, ) -> list[Component]: """Recursively traverse component and subcomponents and return a sequence of them. @@ -532,14 +533,15 @@ def walk( Parameters: name: The name of the component, such as ``VEVENT``, or ``None``. select: A function that takes the component as its first argument - and returns either ``True`` or ``False``. + and returns either ``True`` or ``False``. Default is ``None``, + which selects all components. Returns: A list of components that match. """ if name is not None: name = name.upper() - return self._walk(name, select) + return self._walk(name, select or self.__identity) def with_uid(self, uid: str) -> list[Component]: """Return a list of components with the given UID. @@ -692,7 +694,7 @@ def to_ical(self, sorted: bool = True) -> bytes: Parameters: sorted: Whether parameters and properties should be - lexicographically sorted. + lexicographically sorted. Default is ``True``. Returns: The iCalendar representation of the component. diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index d8599266b..97d44bf29 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -58,7 +58,8 @@ def data_encode( Parameters: data: Required. The data structure to encode. - encoding: The encoding to use in the conversion. + encoding: The encoding to use in the conversion. Default is + ``DEFAULT_ENCODING``, set in :mod:`parser_tools`. Returns: The encoded data structure. From e27bfd2fc9f34c9c34e74da008a4191df763a8c2 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal <315737484+AhmadBilalDSA@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:53:03 +0500 Subject: [PATCH 22/22] docs: sort parameters and clarify walk in component docstrings Prompt: Apply the remaining reviewer feedback on parameter ordering, required markers, walk select description, and the change log wording. Model: DeepSeek V4.1 Flash Free via opencode. Output: this commit. --- news/1749.documentation | 2 +- src/icalendar/cal/component.py | 39 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/news/1749.documentation b/news/1749.documentation index c8062a393..bd2c0d19f 100644 --- a/news/1749.documentation +++ b/news/1749.documentation @@ -1 +1 @@ -Converted docstrings in :mod:`~icalendar.parser_tools.py` and :mod:`~icalendar.cal.component.py` to Google Style. I used AI to assist me with this change. @AhmadBilalDSA \ No newline at end of file +Converted docstrings in :mod:`~icalendar.parser_tools.py` and :mod:`~icalendar.cal.component.py` to Google Style. I used AI to assist me with this change. @AhmadBilalDSA diff --git a/src/icalendar/cal/component.py b/src/icalendar/cal/component.py index 1641a9f95..7c4055556 100644 --- a/src/icalendar/cal/component.py +++ b/src/icalendar/cal/component.py @@ -318,14 +318,14 @@ def _encode( :meta private: Parameters: - name (str): Required. Name of the property. - value (obj): Required. Value of the property. Either a native Python type or - any of icalendar's own property types. - encode (bool): ``True`` if the value should be encoded to one of + name: Required. Name of the property. + value: Required. Value of the property. Either a native Python + type or any of icalendar's own property types. + encode: ``True`` if the value should be encoded to one of icalendar's own property types (falls back to ``vText``), or ``False`` if not. Default is ``True``. - parameters (dict or None): Property parameter dictionary for the value. - Only used if ``encode`` is set to ``True``. + parameters: Property parameter dictionary for the value. Only + used if ``encode`` is set to ``True``. Returns: The encoded icalendar property value. @@ -379,17 +379,14 @@ def add( RFC requires. Parameters: - name: Name of the property. - value: - Value of the property. Either a basic Python type or any of - icalendar's own property types. - parameters: - Property parameter dictionary for the value. Only consulted - when ``encode`` is ``True``. - encode: - ``True`` if the value should be encoded to one of icalendar's - own property types (fallback is ``vText``); ``False`` to - store the value as-is. Default is ``True``. + name: Required. Name of the property. + value: Required. Value of the property. Either a basic Python type + or any of icalendar's own property types. + encode: ``True`` if the value should be encoded to one of + icalendar's own property types (fallback is ``vText``); + ``False`` to store the value as-is. Default is ``True``. + parameters: Property parameter dictionary for the value. Only + consulted when ``encode`` is ``True``. Returns: ``None`` @@ -467,8 +464,9 @@ def decoded(self, name: str, default: Any = _marker) -> Any: This function returns values compatible with native Python types. Parameters: - default: Required. The value to return if the property is not present. name: Required. The name of the property. + default: The value to return if the property is not present. If + omitted, a ``KeyError`` is raised. Returns: The decoded value of the property, or ``default`` if the @@ -554,8 +552,9 @@ def walk( Parameters: name: Component name to keep, such as ``"VEVENT"``; ``None`` keeps every name. - select: Function that takes a component and returns ``True`` to - keep it. Default is ``None``, which keeps every component. + select: Function that takes a component as its first argument and + returns ``True`` to keep it, or ``False`` otherwise. Default is + ``None``, which keeps every component. Returns: list[Component]: The matching components, starting with this one