Repository navigation
Issue 1930 - #1964
Issue 1930#1964Gabriel2002Can wants to merge 2 commits into
Conversation
|
Thanks for the pull request, @Gabriel2002Can! A maintainer will review it shortly. |
Insufficient dataNot enough activity yet to make a reliable assessment. This is an automated analysis by AgentScan |
|
This pull request did not pass quality checks and AI use is suspected. Please review Contribute and make any necessary amendments. |
niccokunzmann
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Hi, this is nice. Since it you already typed the dict, maybe this is not required?
| 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] = {} |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Why do you use a string here?
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
I am not sure what the difference here is to isinstance. Can you help me understand?
| @@ -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 | |||
There was a problem hiding this comment.
I am not sure if type hints are documentation.
Can you check with other entries in the changelog where type hints appear?
|
@Gabriel2002Can Please resolve the merge conflicts. |
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:
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