[issue31907] doc: Clarify error message when attempting to call function via str.format()
Change by mickey695 : -- versions: +Python 3.10 ___ Python tracker <https://bugs.python.org/issue31907> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31907] doc: Clarify error message when attempting to call function via str.format()
mickey695 added the comment: Happy passover Irit(and/or anyone else celebrating)! While your suggestion is accurate, I can't say whether it's enough or not. This is up to you and the other python language development forum to decide :) -- versions: -Python 3.10 ___ Python tracker <https://bugs.python.org/issue31907> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31907] Clarify error message when attempting to call function via str.format()
mickey695 added the comment: Well, it has been more than the 2 weeks I promised however now I finally have time to look into this. I did some fuzzing to build a list quickly and the following ASCII characters can not be used as part of the argument name: exclamation mark(!) period(.) colon(:) opening square bracket([) opening/closing curly brackets({}) also, the argument name may not start with digits from zero to nine(0-9) Basically what needs to be changed is arg_name under the section "Format String Syntax" in \Doc\library\string.rst Problem is, I really don't understand the syntax of the Python/sphinx formal language. The following expression is what I came up with: arg_name ::= [^`decinteger`] [ | `integer` ]+ If anyone from the documentation team could look into it I would be grateful. Moreover, I think attribute_name should probably be changed as it does not have to be a valid identifier. In fact, it can be any text. Eric V. Smiths' example can be used with any text as the attribute name. A comment should be added to the aforementioned section explaining that normally only valid identifiers are accepted, however by implementing your own __getattr__ this can be changed. -- components: +Documentation ___ Python tracker <https://bugs.python.org/issue31907> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31907] Clarify error message when attempting to call function via str.format()
mickey695 added the comment: I think it should be documented properly. In roughly two weeks I will have some time to look into it. So I could probably document the current behaviour by the start of December(unless someone beats me to it) -- ___ Python tracker <https://bugs.python.org/issue31907> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31907] Clarify error message when attempting to call function via str.format()
New submission from mickey695 : 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 <https://bugs.python.org/issue31907> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com