r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.72k stars 101 forks source link

int_convert: Memory effect regarding number-base if parser is used multiple times #121

Closed jenisys closed 4 years ago

jenisys commented 4 years ago

RELATED TO NUMBER-FORMAT: :d Bug was probably introduced in v1.15.0 when „int_convert()“ function was replaced by Callable class that remembers number-base auto-detection as attribute. When the parser object is used the second time, the first discovered number-base is used instead of performing auto-discovery of base again.

EXAMPLE:

import parse
parser = parse.Parser(„{:d}“)
assert parser.parse(„0x12“).fixed[0] == 18.  # OK, but now base=16 was discovered in type-converter
assert parser.parse(„12“) .fixed[0] == 12  # FAILS: 18 again, because base=16 is used again instead of using base=10
jenisys commented 4 years ago

LESSON LEARNT: Type converters should be immutable (before first usage).

jenisys commented 4 years ago

DUPLICATES: #119

r1chardj0n3s commented 4 years ago

fixed in #119

r1chardj0n3s commented 4 years ago

Released as 1.18.0