Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6054e65
docs: convert docstrings to Google style in parser_tools and componen…
AhmadBilalDSA Sep 1, 2026
76f2f5d
docs: add changelog entry for #1072 (#1749)
AhmadBilalDSA Sep 1, 2026
f97f8b4
chore: move news fragment to docs/changelog/1749.doc.rst
AhmadBilalDSA Sep 1, 2026
477436b
chore: move news fragment to docs/changelog/1749.doc.rst (#1749)
AhmadBilalDSA Sep 1, 2026
dc1c8b2
docs: add news fragment 1749.doc.rst and 1072.doc.rst
AhmadBilalDSA Sep 1, 2026
9d657db
docs: add towncrier news fragment at news/1072.documentation.rst (#1749)
AhmadBilalDSA Sep 1, 2026
b3d3465
docs: revert Args to Parameters per style guide and format with ruff
AhmadBilalDSA Sep 4, 2026
f97810a
Merge branch 'main' into fix/typing-prop-components
stevepiercy Sep 6, 2026
f77ddbd
docs: rename news fragment to PR 1749
AhmadBilalDSA Sep 6, 2026
c19c3da
Apply suggestion from @stevepiercy
AhmadBilalDSA Sep 6, 2026
7f0a9f6
Update src/icalendar/parser_tools.py
AhmadBilalDSA Sep 6, 2026
08393c1
Update src/icalendar/parser_tools.py
AhmadBilalDSA Sep 6, 2026
4aa8354
Update src/icalendar/parser_tools.py
AhmadBilalDSA Sep 6, 2026
fcdc71f
Update src/icalendar/cal/component.py
AhmadBilalDSA Sep 6, 2026
0648b96
Update src/icalendar/cal/component.py
AhmadBilalDSA Sep 6, 2026
e76e222
Update src/icalendar/cal/component.py
AhmadBilalDSA Sep 6, 2026
e144079
Update src/icalendar/cal/component.py
AhmadBilalDSA Sep 6, 2026
f25b927
Update src/icalendar/cal/component.py
AhmadBilalDSA Sep 6, 2026
6335df6
Merge branch 'main' into fix/typing-prop-components
AhmadBilalDSA Sep 6, 2026
863d389
typing: add type hints to Component.walk (#938, #1749)
AhmadBilalDSA Sep 6, 2026
253c9f6
docs: address remaining docstring review feedback and update changelo…
AhmadBilalDSA Sep 10, 2026
4e241c1
Merge branch 'main' into fix/typing-prop-components
AhmadBilalDSA Sep 10, 2026
47d462a
Merge branch 'main' into fix/typing-prop-components
angatha Oct 15, 2026
0a02d22
Fix my parts of the PR
angatha Oct 25, 2026
68f4e25
Merge branch 'main' into fix/typing-prop-components
angatha Oct 25, 2026
c720885
Merge branch 'main' into fix/typing-prop-components
AhmadBilalDSA Oct 30, 2026
fc136b5
docs: apply final docstring review feedback
AhmadBilalDSA Nov 25, 2026
a5101df
Merge upstream/main into fix/typing-prop-components
AhmadBilalDSA Nov 25, 2026
e27bfd2
docs: sort parameters and clarify walk in component docstrings
AhmadBilalDSA Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1749.documentation
Original file line number Diff line number Diff line change
@@ -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
113 changes: 76 additions & 37 deletions src/icalendar/cal/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from icalendar.tools import is_date

if TYPE_CHECKING:
from collections.abc import Iterable
from collections.abc import Callable, Iterable, Sequence

from icalendar.compatibility import Self

Expand Down Expand Up @@ -190,7 +190,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: Required. The name of the component, such as ``VCALENDAR``.

Returns:
The component class registered for ``name``.
"""
return cls._get_component_factory().get_component_class(name)

Expand Down Expand Up @@ -303,20 +306,26 @@ 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,
Comment thread
angatha marked this conversation as resolved.
Resolved
) -> Any:
"""Encode values to icalendar property values.

: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.
parameters (dict or None): Property parameter dictionary for the value.
Only used if ``encode`` is set to ``True``.
or ``False`` if not. Default is ``True``.
parameters: Property parameter dictionary for the value. Only
used if ``encode`` is set to ``True``.

Returns:
Comment thread
AhmadBilalDSA marked this conversation as resolved.
Resolved
The encoded icalendar property value.
Expand Down Expand Up @@ -370,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.
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``
Expand Down Expand Up @@ -452,10 +458,19 @@ 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: 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
property is not present.
"""
if name in self:
value = self[name]
Expand All @@ -477,12 +492,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):
"""Converts a list of values into comma separated string and sets value
to that.
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 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=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))

#########################
Expand All @@ -493,7 +518,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.

Expand All @@ -508,10 +533,15 @@ 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] | None = None,
) -> list[Component]:
"""Return this component and its subcomponents that match the filters.

Expand All @@ -522,16 +552,17 @@ 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. By default, every component is kept.
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
if it matches.
"""
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.
Expand Down Expand Up @@ -684,10 +715,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.

Parameters:
sorted: Whether parameters and properties should be
lexicographically sorted. Default is ``True``.

Returns:
The iCalendar representation of the component.
"""

content_lines = self.content_lines(sorted=sorted)
Expand Down Expand Up @@ -989,6 +1025,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.
Expand Down Expand Up @@ -1402,7 +1439,9 @@ def from_xcal(cls, xcal: Element | bytes | Path | BinaryIO) -> list[Self]:
return components


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.

:meta private:
Expand Down
12 changes: 10 additions & 2 deletions src/icalendar/parser_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def to_unicode(value: ICAL_TYPE, encoding: str = "utf-8-sig") -> str:
Parameters:
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
Expand All @@ -52,12 +55,17 @@ 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.

Parameters:
data: The datastructure to encode.
data: Required. The data structure to encode.
encoding: The encoding to use in the conversion. Default is
``DEFAULT_ENCODING``, set in :mod:`parser_tools`.

Returns:
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):
Expand Down