> Formatter Creation and Initialization > > The Formatter class takes a single initialization argument, 'flags': > > Formatter(flags=0) > > The 'flags' argument is used to control certain subtle behavioral > differences in formatting that would be cumbersome to change via > subclassing. The flags values are defined as static variables > in the "Formatter" class: > > Formatter.ALLOW_LEADING_UNDERSCORES > > By default, leading underscores are not allowed in identifier > lookups (getattr or getitem). Setting this flag will allow > this. > > Formatter.CHECK_UNUSED_POSITIONAL > > If this flag is set, the any positional arguments which are > supplied to the 'format' method but which are not used by > the format string will cause an error. > > Formatter.CHECK_UNUSED_NAME > > If this flag is set, the any named arguments which are > supplied to the 'format' method but which are not used by > the format string will cause an error.
I'm not sure I'm wild about these flags which would have to be or'd together, as opposed to discrete parameters. I realize have a single flag field is likely more extensible, but my impression of the standard library is a move away from bitfield flags. Perhaps that's only in my own mind, though! Also, why put this in the base class at all? These could all be implemented in a derived class (or classes), which would leave the base class state-free and therefore without a constructor. > Formatter Methods > > The methods of class Formatter are as follows: > > -- format(format_string, *args, **kwargs) > -- vformat(format_string, args, kwargs) > -- get_positional(args, index) > -- get_named(kwds, name) > -- format_field(value, conversion) I've started a sample implementation to test this API. For starters, I'm writing it in pure Python, but my intention is to use the code in the pep3101 sandbox once I have some tests written and we're happy with the API. _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com