Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"{ +(}".format(**{' +(': 44}) should produce ValueError: invalid identifier, ' +(' in format #46850

Closed
dangyogi mannequin opened this issue Apr 8, 2008 · 5 comments
Closed
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@dangyogi
Copy link
Mannequin

dangyogi mannequin commented Apr 8, 2008

BPO 2598
Nosy @abalkin, @ericvsmith

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ericvsmith'
closed_at = <Date 2008-05-20.11:35:57.875>
created_at = <Date 2008-04-08.19:38:42.470>
labels = ['interpreter-core', 'type-bug']
title = '"{ +(}".format(**{\' +(\': 44}) should produce ValueError: invalid identifier, \' +(\' in format'
updated_at = <Date 2008-05-20.11:41:57.750>
user = 'https://bugs.python.org/dangyogi'

bugs.python.org fields:

activity = <Date 2008-05-20.11:41:57.750>
actor = 'eric.smith'
assignee = 'eric.smith'
closed = True
closed_date = <Date 2008-05-20.11:35:57.875>
closer = 'eric.smith'
components = ['Interpreter Core']
creation = <Date 2008-04-08.19:38:42.470>
creator = 'dangyogi'
dependencies = []
files = []
hgrepos = []
issue_num = 2598
keywords = []
message_count = 5.0
messages = ['65209', '65265', '65404', '67122', '67123']
nosy_count = 3.0
nosy_names = ['belopolsky', 'eric.smith', 'dangyogi']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2598'
versions = ['Python 3.0']

@dangyogi
Copy link
Mannequin Author

dangyogi mannequin commented Apr 8, 2008

Format strings are documented to only allow identifiers or integers as
the field_name, but allow almost anything.

Python 3.0a3

@dangyogi dangyogi mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 8, 2008
@abalkin
Copy link
Member

abalkin commented Apr 9, 2008

This is a feature explained in PEP-3101:

"""
Implementation note: The implementation of this proposal is
not required to enforce the rule about a simple or dotted name
being a valid Python identifier. Instead, it will rely on the
getattr function of the underlying object to throw an exception if
the identifier is not legal. The str.format() function will have
a minimalist parser which only attempts to figure out when it is
"done" with an identifier (by finding a '.' or a ']', or '}',
etc.).
""" <http://www.python.org/dev/peps/pep-3101\>

Why is that a problem for you?

@dangyogi
Copy link
Mannequin Author

dangyogi mannequin commented Apr 12, 2008

I was reading the 3.0 documentation:
http://docs.python.org/dev/3.0/library/string.html#formatstrings which
indicated that an identifier was required. I was unaware of the
implementation note in the PEP.

They only issue remaining is that for the example in the title of this
issue, "{ +(}".format(**{' +(': 44}), no error is generated. I agree
that this is a nit and presumably the will of the community reviewing
the PEP, so agree to having the issue rejected.

I would reject it myself, but am unable to do so...

Thank you for pointing out the PEP to me.

@ericvsmith ericvsmith self-assigned this May 6, 2008
@ericvsmith
Copy link
Member

After discussing this with Talin, we've decided this is "works as
designed". The problem, if any, is that **{' +(': 44} is allowed as a
parameter. I think that perhaps that should be an error, but I haven't
had time to research if this is already a known issue.

@ericvsmith
Copy link
Member

I should have been clearer. By "The problem, if any, is that **{' +(':
44} is allowed as a parameter", I meant in general, for all
function/method calls. It's not an issue that's restricted to str.format().

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants