FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Raise ParserError for an interval with mismatched endpoint types by eeshsaxena · Pull Request #992 · python-pendulum/pendulum · GitHub

Raise ParserError for an interval with mismatched endpoint types - #992

Open
eeshsaxena wants to merge 1 commit into
python-pendulum:masterfrom
eeshsaxena:fix/interval-mismatched-ends
Open

Raise ParserError for an interval with mismatched endpoint types#992
eeshsaxena wants to merge 1 commit into
python-pendulum:masterfrom
eeshsaxena:fix/interval-mismatched-ends

Conversation

Copy link
Copy Markdown

pendulum.parse('2020-01-01/12:30:00') raises TypeError: unsupported operand type(s) for -: 'Time' and 'datetime.date' instead of a ParserError.

The / makes parse treat the string as an ISO 8601 interval. Here one side parses to a date and the other to a bare time, and building the interval computes end - start (Time - date), which is undefined. The same happens for time/time (12:00:00/13:00:00) and time/date. Valid intervals (datetime/datetime, date/date) are unaffected.

I wrapped the two-endpoint pendulum.interval(...) construction in _parse so a TypeError there is re-raised as ParserError, which is what parse already raises for other invalid input (and it subclasses ValueError, so existing except ValueError handlers still work).

Added a test in test_parsing.py covering the mismatched cases; it raises TypeError on master and passes with the change, and the rest of the parsing tests still pass. Found it by fuzzing parse with mutated date strings.

pendulum.parse treats 'A/B' as an ISO 8601 interval. When one side parses to a
date and the other to a bare time (e.g. '2020-01-01/12:30:00'), building the
interval does Time - date and raised a bare TypeError out of parse(). Same for
time/time and time/date. Convert that TypeError into a ParserError so callers
get the documented parse error instead.

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Raise ParserError for an interval with mismatched endpoint types), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining pendulum!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

1 participant


Back | FazBrowse Home | New Git URL