Skip to content

Parse month- and day-level consecutives in sets - #94

Merged
cameron-simpson merged 1 commit into
ixc:mainfrom
lisboarocha:fix-79-month-day-consecutives
Sep 16, 2026
Merged

cameron-simpson merged 1 commit into
ixc:mainfrom
lisboarocha:fix-79-month-day-consecutives

Conversation

@lisboarocha

Copy link
Copy Markdown
Contributor

Fixes #79.

Sets with a range of months or days did not parse:

>>> parse_edtf("[1774-11..1774-12]")
TypeError: Consecutives.__init__() got an unexpected keyword argument 'year'

Two things went wrong in consecutives. The results names inside a month or day bound (year, month, day) reached the token dict, so Consecutives(**kwargs) received them as keyword arguments; and each bound arrived as the list of its parts (['1774', '-', '11']) rather than as a string, which is what year_basic works around for years.

The fix:

  • grammar.py: the month and day bounds are wrapped in Combine, so each is one string ("1774-11").
  • parser_classes.py: Consecutives.parse_action builds the object from lower and upper only, taking the combined string out of the ParseResults that Combine returns when the bound keeps inner results names.

Tests: four examples added to EXAMPLES in tests/test_parser.py, from the issue and the specification's set forms:

  • [1774-11..1774-12] → 1774-11-01 .. 1774-12-31
  • [1785-07-30..1785-08-06] → 1785-07-30 .. 1785-08-06
  • [1667, 1912-03..1912-05] → 1667-01-01 .. 1912-05-31
  • {1912-03..1912-05} → 1912-03-01 .. 1912-05-31

The four failed before the change; with it the suite gives 290 passed, 22 deselected (286 before), and ruff check and ruff format --check pass on the changed files.

[1774-11..1774-12] and [1785-07-30..1785-08-06] raised TypeError: the
results names inside a month or day bound (year, month, day) reached
Consecutives.__init__ as keyword arguments, and each bound arrived as a
list of its parts. The bounds are now combined into one string, and
Consecutives builds itself from the two bounds only.
@aweakley

Copy link
Copy Markdown
Member

@cameron-simpson please can you look at this one?

@cameron-simpson

Copy link
Copy Markdown
Collaborator

This seems correct to me. Thank you @lisboarocha

@cameron-simpson
cameron-simpson merged commit 79f75ce into ixc:main Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One of a set only works with full year

3 participants