You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use pint to parse simple time-delta patterns, and in my code I made the (wrong) assumption that it will error on weirder input that isn't of the form .
However when I run
import pint
ureg = pint.UnitRegistry()
ureg.parse_expression('4 days 10:10:21')
It returns 8400 <Unit('day')>, which is 8400 = 21 * 10 * 10 * 4, so it makes some sense in that it is multiplying all of the numbers, but why isn't it choking on those colons?
This expression is supposed to represent 4 days, 10 hours, 10 minutes, and 21 seconds, although I don't expect pint to parse that, but I did expect that it wouldn't accept it. I'm curious what parser rules are allowing this to pass, and if they were made more strict would that break other use cases?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use pint to parse simple time-delta patterns, and in my code I made the (wrong) assumption that it will error on weirder input that isn't of the form .
However when I run
It returns
8400 <Unit('day')>
, which is 8400 = 21 * 10 * 10 * 4, so it makes some sense in that it is multiplying all of the numbers, but why isn't it choking on those colons?This expression is supposed to represent 4 days, 10 hours, 10 minutes, and 21 seconds, although I don't expect pint to parse that, but I did expect that it wouldn't accept it. I'm curious what parser rules are allowing this to pass, and if they were made more strict would that break other use cases?
Beta Was this translation helpful? Give feedback.
All reactions