[formatter] add 'format-operator-dot' option
to allow disabling the behavior introduced in commit
a79a945494
This commit is contained in:
@@ -9376,6 +9376,22 @@ Description
|
||||
by using a `defaultdict <https://docs.python.org/3/library/collections.html#collections.defaultdict>`__
|
||||
|
||||
|
||||
format-operator-dot
|
||||
-------------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
``true``
|
||||
Description
|
||||
In standard `Format Strings`_, allow the `dot` operator ``.``
|
||||
to function as a general access operator
|
||||
in addition to regular attribute access.
|
||||
|
||||
* ``obj.attribute``
|
||||
* ``dict.fieldname``
|
||||
* ``list.123``
|
||||
|
||||
|
||||
format-separator
|
||||
----------------
|
||||
Type
|
||||
|
||||
@@ -120,7 +120,10 @@ def main():
|
||||
elif filterenv.startswith("default"):
|
||||
util.compile_expression = util.compile_expression_defaultdict
|
||||
|
||||
# format string separator
|
||||
# format string options
|
||||
if not config.get((), "format-operator-dot", True):
|
||||
from . import formatter
|
||||
formatter._attrgetter = formatter.operator.attrgetter
|
||||
if separator := config.get((), "format-separator"):
|
||||
from . import formatter
|
||||
formatter._SEPARATOR = separator
|
||||
|
||||
Reference in New Issue
Block a user