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 2012年01月16日 05:05 by Jim.Jewett, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg151320 - (view) | Author: Jim Jewett (Jim.Jewett) * (Python triager) | Date: 2012年01月16日 05:05 | |
The documentation for hasattr, getattr, and delattr state that they are equivalent to object.attribute access; this isn't quite true, because object.attribute uses a NFKC-normalized version of the string as only the secondary location, while hasattr, getattr, and delattr (assuming an object rather than an Identifier or string) don't seem to do the normalization at all. I think the simplest fix would be to normalize and retry when hasattr, getattr, and delattr fail with a string, but I'm not sure that normalization shouldn't be the only string tried. >>> o.o Traceback (most recent call last): File "<pyshell#820>", line 1, in <module> o.o AttributeError: 'Object' object has no attribute 'o' >>> o.o Traceback (most recent call last): File "<pyshell#821>", line 1, in <module> o.o AttributeError: 'Object' object has no attribute 'o' >>> o.o=[] >>> hasattr(o, "o") False >>> getattr(o, "o") Traceback (most recent call last): File "<pyshell#824>", line 1, in <module> getattr(o, "o") AttributeError: 'Object' object has no attribute 'o' >>> delattr(o, "o") Traceback (most recent call last): File "<pyshell#825>", line 1, in <module> delattr(o, "o") AttributeError: o >>> o.o [] >>> o.o is o.o True >>> o.o [] >>> del o.o >>> o.o Traceback (most recent call last): File "<pyshell#830>", line 1, in <module> o.o AttributeError: 'Object' object has no attribute 'o' >>> o.o = 5 >>> hasattr(o, "o") False >>> hasattr(o, "o") True >>> hasattr(o, "o") True >>> o.o 5 >>> delattr(o, "o") >>> o.o |
|||
| msg151371 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2012年01月16日 15:10 | |
Normalizing the string in getattr() is unacceptable. We'll just have to document, that all identifiers are in NFKC. |
|||
| msg151405 - (view) | Author: Jim Jewett (Jim.Jewett) * (Python triager) | Date: 2012年01月16日 20:14 | |
Why is normalization in getattr unacceptable? I won't pretend to *like* it, but the difference between two canonically equal strings really is (by definition) just a representational issue. Would it be OK to normalize in object's own implementation, so that custom classes could avoid the normalization, but it would happen by default? |
|||
| msg151407 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2012年01月16日 20:21 | |
Because it's (very) expensive and the method you propose would fail in the case that someone had put the normalized and unnormalized string in the object's __dict__. |
|||
| msg151806 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2012年01月23日 10:23 | |
I concur with Benjamin on all counts. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:25 | admin | set | github: 58002 |
| 2018年01月02日 17:52:57 | benjamin.peterson | link | issue32483 superseder |
| 2012年01月23日 14:03:22 | benjamin.peterson | set | status: open -> closed resolution: wont fix |
| 2012年01月23日 10:23:05 | rhettinger | set | nosy:
+ rhettinger messages: + msg151806 |
| 2012年01月16日 20:21:20 | benjamin.peterson | set | messages: + msg151407 |
| 2012年01月16日 20:14:14 | Jim.Jewett | set | messages: + msg151405 |
| 2012年01月16日 15:10:30 | benjamin.peterson | set | messages: + msg151371 |
| 2012年01月16日 12:22:51 | pitrou | set | nosy:
+ benjamin.peterson versions: + Python 3.2, Python 3.3 |
| 2012年01月16日 05:05:25 | Jim.Jewett | create | |