Skip to content

Issue 1930 - #1964

Open
Gabriel2002Can wants to merge 2 commits into
PyCalendar:mainfrom
Gabriel2002Can:issue-1930
Open

Gabriel2002Can wants to merge 2 commits into
PyCalendar:mainfrom
Gabriel2002Can:issue-1930

Conversation

@Gabriel2002Can

Copy link
Copy Markdown

Linked issue

Description

Hi! This is my first open source contribution! I'm working on this as part of an assignment.

I know there's already another PR #1959 addressing this issue, but I believe my implementation tackles different parts of the problem. And I didn't want all my work to go to waste!

Since #1930 is a follow up to #1858, my goal was to define the expected value types stored in vRecur, with the generic CaselessDict introduced in the previous issue.

Here's what I changed:

  • Added RecurValue and RecurEntryValue type aliases to represent the expected values.
  • Updated vRecur to inherit from CaselessDict[RecurEntryValue], improving type checking and autocomplete when using dict values.
  • Added a few supporting type annotations and casts to keep things compatible with mypy.
  • Updated the canonical_order annotation in CaselessDict to support the key order defined by subclasses.
  • Added tests.

The other PR seems to focus more on typing method signatures, and mine focuses on the values stored in the dict itself. So I think both approaches could complement each other!

Since this is my first contribution, any feedback or suggestions would be really appreciated!

Checklist

  • I added a change log entry, following the instructions in all subsections under Change log requirements.
  • I followed icalendar's Artificial intelligence policy and disclosed my Responsible AI use in my commit messages, if applicable.
  • I added or updated tests, if applicable.
  • I ran and ensured all tests pass locally by following Run tests.
  • I added or edited documentation as necessary, both as docstrings to be rendered in the API documentation and narrative documentation, following the Style guide.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @Gabriel2002Can! A maintainer will review it shortly.

@github-actions

Copy link
Copy Markdown
Contributor

Insufficient data

Not enough activity yet to make a reliable assessment.

View full analysis →

This is an automated analysis by AgentScan

@github-actions github-actions Bot added the ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding. label Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request did not pass quality checks and AI use is suspected. Please review Contribute and make any necessary amendments.

@niccokunzmann niccokunzmann left a comment

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.

Thanks, this is a really good PR.

I left some ideas and questions as comments. Let me know what you think!

result = []
for key, vals in self.sorted_items():
typ = self.types.get(key, vText)
typ: Any = self.types.get(key, vText)

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.

Hi, this is nice. Since it you already typed the dict, maybe this is not required?

Suggested change
typ: Any = self.types.get(key, vText)
typ = self.types.get(key, vText)

"""The jCal representation of this property according to :rfc:`7265`."""
recur = {}
for k, v in self.sorted_items():
recur: dict[str, 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.

Typing wise, we can assume here that all values are JSON compatible.
Any is good enough.

If you want to make it perfect: https://datatracker.ietf.org/doc/html/rfc7265#section-3.6.10

No need to change it though.

recur[key.lower()] = values
for i, v in enumerate(value):
with JCalParsingError.reraise_with_path_added(i):
values.append(value_type.parse_jcal_value(v))

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.

This can be a follow-up if you like in another PR. It might need the type hints to be stored somewhere else to avoid circular imports or maybe the functions can just return an explicit type that is compatible.

value = values[0] if isinstance(values, SEQUENCE_TYPES) else values
try:
return int(value)
return int(cast("int | str", value))

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.

Why do you use a string here?

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.

Probably, it is clear that if that does not work, then we could also guide this with a isinstance check. But I think, it is wrong because the TypeError is caught below.

@@ -0,0 +1,17 @@
from typing_extensions import assert_type

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, typing_extensions might not always be installed?
It would live in icalendar.compatibility with a Python version check.

def test_vrecur_value_type():
rule = vRecur.from_ical("FREQ=DAILY;COUNT=10")

assert_type(rule["COUNT"], RecurEntryValue)

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 am not sure what the difference here is to isinstance. Can you help me understand?

Comment thread news/1930.documentation.1
@@ -0,0 +1 @@
Added value type hints to :class:`~icalendar.prop.recur.recur.vRecur`. Also updated the ``CaselessDict.canonical_order`` type annotation to support subclass key ordering. @Gabriel2002Can No newline at end of file

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 am not sure if type hints are documentation.
Can you check with other entries in the changelog where type hints appear?

@niccokunzmann

Copy link
Copy Markdown
Member

@Gabriel2002Can Please resolve the merge conflicts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-suspicion This contribution is possibly created with lots of AI help without enough human understanding.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants