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 2016年10月11日 21:38 by David Eyk, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| comp_scope.py | David Eyk, 2016年10月11日 21:38 | |||
| Messages (3) | |||
|---|---|---|---|
| msg278505 - (view) | Author: David Eyk (David Eyk) | Date: 2016年10月11日 21:38 | |
I've discovered what appears to be a scoping bug in Python 3.5.1, where the class scope is not available inside a list comprehension defined in the class scope. Attached is a simple example script, also available at the following gist: https://gist.github.com/eykd/c63a7cf760a538ee8bc3828362ed12e3 As demonstrated, the script runs fine in Python 2.7.11, but fails in 3.5.1. I can't think of any good reason why the class scope wouldn't be available to the comprehension scope, but if there is a reason, I'm keen to know what it is! |
|||
| msg278510 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2016年10月11日 23:20 | |
See issue 11796, and the issue it is marked as a duplicate of, for an explanation. |
|||
| msg278512 - (view) | Author: David Eyk (David Eyk) | Date: 2016年10月12日 00:01 | |
Thanks for the pointer. That seems weird and arbitrary when you think of it in terms of scope, but what can you do? All the same, thanks for the quick response. :) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:38 | admin | set | github: 72605 |
| 2016年10月12日 00:01:04 | David Eyk | set | messages: + msg278512 |
| 2016年10月11日 23:20:48 | r.david.murray | set | status: open -> closed superseder: Comprehensions in a class definition mostly cannot access class variable nosy: + r.david.murray messages: + msg278510 resolution: duplicate stage: resolved |
| 2016年10月11日 21:38:57 | David Eyk | create | |