python-bibtexparser icon indicating copy to clipboard operation
python-bibtexparser copied to clipboard

Confusing option setting for the parser

Open omangin opened this issue 6 years ago • 4 comments

Some options have to be set when the parser object is created like common_strings because they are treated in the __init__, others can be changed until the parsing occurs by doing some parser.option = new_value.

This behavior is confusing and should be improved to convey more clearly what the parser object does and retain. It is not clear which approach to this is best: loading default strings could be delayed to just before parsing, or setting options directly could be deprecated.

See also #222.

omangin avatar Oct 07 '18 05:10 omangin

Another option is to add a setter function for common_strings that calls load_common_strings(). I think this is better than loading the strings before parsing, although it's a little ugly syntactically.

tqbl avatar Oct 09 '18 14:10 tqbl

The issue then is that doing

parser.common_strings = True
parser.common_strings = False

would not behave as expected since the second one would have no effect. We could then raise an exception if on attempts to set the value to False but the point is that the semantics of the option (set at the creation of the parser and not changeable afterwards) is not matching the semantics of how it is set.

omangin avatar Oct 12 '18 03:10 omangin

True, but wouldn't this also be a problem if you loaded the strings before parsing? In principle, the user could set it to false after parsing once and then try to parse again.

Without fully checking the source code, adding self.bib_database.strings = OrderedDict() for the second statement should work. It would override strings added by previous parse actions, but shouldn't lead to errors.

tqbl avatar Oct 12 '18 11:10 tqbl

Indeed but it requires the user to know and interact with what is supposed to be implementation details.

Here I would say that if we want to allow that we should provide a method for resetting the string database instead.

omangin avatar Dec 04 '18 07:12 omangin

fixed in v2

MiWeiss avatar May 26 '23 13:05 MiWeiss