This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年03月15日 08:21 by serhiy.storchaka, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| string_formatting_self.patch | serhiy.storchaka, 2015年03月15日 08:21 | review | ||
| string_formatting_self_2.patch | serhiy.storchaka, 2015年03月20日 09:41 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg238132 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年03月15日 08:21 | |
string.Template doesn't allow to specify the self substitute parameter as keyword argument.
>>> import string
>>> string.Template('the self is $self').substitute(self='bozo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: substitute() got multiple values for argument 'self'
>>> string.Template('the self is $self').safe_substitute(self='bozo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: safe_substitute() got multiple values for argument 'self'
The same issue is with string.Formatter.format:
>>> string.Formatter().format('the self is {self}', self='bozo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: format() got multiple values for argument 'self'
Proposed patch fixes these issues.
|
|||
| msg238631 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年03月20日 09:41 | |
Updated patch addresses Paul's and Demian's comments. Converting the format_string parameter to positional parameter can break third-party code, so this needs a deprecation period. |
|||
| msg239177 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2015年03月24日 20:31 | |
New changeset 1c19778123a3 by Serhiy Storchaka in branch '2.7': Issue #23671: string.Template now allows to specify the "self" parameter as https://hg.python.org/cpython/rev/1c19778123a3 New changeset 7a4b499c4dc0 by Serhiy Storchaka in branch '3.4': Issue #23671: string.Template now allows to specify the "self" parameter as https://hg.python.org/cpython/rev/7a4b499c4dc0 New changeset 0dd263949e41 by Serhiy Storchaka in branch 'default': Issue #23671: string.Template now allows to specify the "self" parameter as https://hg.python.org/cpython/rev/0dd263949e41 |
|||
| msg239183 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2015年03月24日 21:28 | |
This is a nice catch of a subtle bug and a nice fix. I verified that replacing 'self' with '*args' does not simply shift the problem from 'self' to 'args'.
>>> class C:
def test(*args, **kwargs):
print(args, kwargs )
>>> c = C()
>>> c.test(1, args=2, kwargs=3, self=4)
(<__main__.C object at 0x00000000035FE128>, 1) {'args': 2, 'kwargs': 3, 'self': 4}
While the * and ** names are, like parameter names, local names given in the signature header, they are not counted as parameter names in the code object .co_argcount or .co_kwonlyargcount attributes that are used along with co_varnames in the name-argument matching process.
|
|||
| msg239412 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2015年03月27日 15:58 | |
"descriptor 'substitute' of 'Template' object needs an argument" These error messages don’t seem very user-friendly. I think the style in the rest of the module is like "substitute method wants x y z". |
|||
| msg239414 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年03月27日 16:13 | |
It matches error messages generated by builtin unbound methods.
>>> str.format()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'format' of 'str' object needs an argument
It would be incorrect to say "substitute method wants x y z", because the substitute method doesn't need any arguments.
>>> string.Template('spam').substitute()
'spam'
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:13 | admin | set | github: 67859 |
| 2015年03月27日 16:13:15 | serhiy.storchaka | set | messages: + msg239414 |
| 2015年03月27日 15:58:34 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg239412 |
| 2015年03月24日 21:28:27 | terry.reedy | set | nosy:
+ terry.reedy messages: + msg239183 |
| 2015年03月24日 20:33:12 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2015年03月24日 20:31:58 | python-dev | set | nosy:
+ python-dev messages: + msg239177 |
| 2015年03月24日 20:06:37 | serhiy.storchaka | set | assignee: serhiy.storchaka |
| 2015年03月20日 09:41:57 | serhiy.storchaka | set | files:
+ string_formatting_self_2.patch messages: + msg238631 |
| 2015年03月15日 08:21:34 | serhiy.storchaka | create | |