From: Steve H. <SHowell@DevIS.com> - 2002-12-12 14:27:45
|
On Mon, 2002-12-09 at 14:13, Tim Hochberg wrote: > > I just signed up to this mailing list and perhaps this should be going > straight to Steve Howell, so chastise me if appropriate. > The YAML mailing list has hardly been overwhelmed with PyYaml patches, nor has my inbox. :) Either one's fine by me, and I don't think anybody else objects. > Anyway, I've been using YAML on and off for a few months now and it seems > like a great tool. However I recently bumped into a bug in PyYamls handling > of numbers in scientific notation. In particular a round trip with the > number 2e-9 results in a string. > > The details: 2e9 gets written out as 2e-009 and when it gets read back this > does not get matched by SCIENTIFIC_REGEX, which requires a dot, so it > instead is read as a string. I suspect the fix is just to relax the regex > to: > > "^[-+]?[0-9][0-9,]*[0-9.]*[eE][-+][0-9]+$" > > You could probably remove the commas from SCIENTIFIC REGEX as well as the > commas after the point in FLOAT_REGEX as well. This would result in: > > FLOAT_REGEX = re.compile("^[-+]?[0-9][0-9,]*\.[0-9]*$") > SCIENTIFIC_REGEX = re.compile^[-+]?[0-9]+(\.[0-9]*)?[eE][-+][0-9]+$") > > FWIW, all tests continue to run fine with these on python 2.2. Disclaimer: > I'm not a regular user of regular expressions, so the above could be > completely bogus and I'd never know. They seem to work though. > > [Alternatively, you could use "^[-+]?[0-9](,?[0-9][0-9][0-9])*\.[0-9]*$" for > the float regex, but that's probably overkill]. > I applied your patch to PyYaml 0.31. Thanks for taking the time to submit it. Cheers, Steve |