Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Change log
Minor changes
~~~~~~~~~~~~~

- ...
- Add type hints to :class:`~icalendar.prop.recur.frequency.vFrequency`. :issue:`938`

Breaking changes
~~~~~~~~~~~~~~~~
Expand Down
10 changes: 5 additions & 5 deletions src/icalendar/prop/recur/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ class vFrequency(str):

def __new__(
cls,
value,
encoding=DEFAULT_ENCODING,
value: Any,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the use of Any is too loose. We have a special variable that you can import. Try this out, and let me know.

Modify the import.

from icalendar.parser_tools import DEFAULT_ENCODING, ICAL_TYPE, to_unicode

Then:

Suggested change
value: Any,
value: ICAL_TYPE,

encoding: str = DEFAULT_ENCODING,
/,
params: dict[str, Any] | None = None,
):
) -> Self:
value = to_unicode(value, encoding=encoding)
self = super().__new__(cls, value)
if self not in vFrequency.frequencies:
raise ValueError(f"Expected frequency, got: {self}")
self.params = Parameters(params)
return self

def to_ical(self):
def to_ical(self) -> bytes:
return self.encode(DEFAULT_ENCODING).upper()

@classmethod
def from_ical(cls, ical):
def from_ical(cls, ical: Any) -> Self:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Suggested change
def from_ical(cls, ical: Any) -> Self:
def from_ical(cls, ical: ICAL_TYPE) -> Self:

try:
return cls(ical.upper())
except Exception as e:
Expand Down