[New-bugs-announce] [issue31907] Clarify error message when attempting to call function via str.format()

mickey695 report at bugs.python.org
Mon Oct 30 20:35:20 EDT 2017


New submission from mickey695 <mickey695 at gmail.com>:

PEP 3101 states that format strings may only use the "."(getattr) or the "[]" (getitem) operators to address either attributes or items of parameters.
Should a programmer attempt to, for example, call a function of a parameter as follows: 

>>> d = datetime.datetime(2017, 10, 31)
>>> "{0.ctime()}".format(d)

they will receive an error message such as:

AttributeError: 'datetime.datetime' object has no attribute 'ctime()'

Proposal:
Raise an error stating that cannot embed arbitrary expressions in str.format() format strings

----------
components: Interpreter Core
messages: 305263
nosy: mickey695
priority: normal
severity: normal
status: open
title: Clarify error message when attempting to call function via str.format()
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31907>
_______________________________________


More information about the New-bugs-announce mailing list