Issue 9259: Python 2.7 breaks assigned __exit__s (original) (raw)

Created on 2010-07-14 11:53 by arielbyd, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)

msg110268 - (view)

Author: Ariel Ben-Yehuda (arielbyd)

Date: 2010-07-14 11:53

Hello, I think there is a problem with Python 2.7: I installed it, and tried to compile GObject-Introspection 0.9.2. Here is the result:

... GISCAN GLib-2.0.gir Traceback (most recent call last): File "../tools/g-ir-scanner", line 36, in from giscanner.scannermain import scanner_main File "/sources/gobject-introspection-0.9.2/giscanner/scannermain.py", line 31, in from giscanner.dumper import compile_introspection_binary File "/sources/gobject-introspection-0.9.2/giscanner/dumper.py", line 26, in from .glibtransformer import IntrospectionBinary File "/sources/gobject-introspection-0.9.2/giscanner/glibtransformer.py", line 34, in from .transformer import Names File "/sources/gobject-introspection-0.9.2/giscanner/transformer.py", line 31, in from .girparser import GIRParser File "/sources/gobject-introspection-0.9.2/giscanner/girparser.py", line 32, in from .girwriter import COMPATIBLE_GIR_VERSION File "/sources/gobject-introspection-0.9.2/giscanner/girwriter.py", line 30, in from .xmlwriter import XMLWriter File "/sources/gobject-introspection-0.9.2/giscanner/xmlwriter.py", line 70, in with LibtoolImporter: AttributeError: exit

Oops, no GObject-Introspection for me. Investigating the bug, I looked in the recent changes in Python2.7 for something interesting, and found this: A new opcode was added to perform the initial setup for with statements, looking up the enter() and exit() methods. (Contributed by Benjamin Peterson.)

Finally, I made 3 test cases to the bug. All 3 produce no input in Python 2.6, but crash pretty nicely in 2.7, the first 2 not finding exit and the last missing enter.

I will try to make a patch, however my CPython skills are not so great, so you will probably make a better one.

msg110274 - (view)

Author: Éric Araujo (eric.araujo) * (Python committer)

Date: 2010-07-14 13:07

Thank you for the report. Unfortunately, the 2.6 behavior was a bug, as I explained on #9220: Magic methods are looked up on the object’s class, not in the object’s dict. <http://docs.python.org/reference/datamodel#specialnames>

(Your test with class methods was a clever idea, but a class is a type instance, so it’s the same behavior: enter is looked up on type, not on the class. Nice try :)

Tip for future bug reports: We prefer regular files over archives. Thanks again!

msg110276 - (view)

Author: Ariel Ben-Yehuda (arielbyd)

Date: 2010-07-14 13:09

Bug or not bug, Python2.7 breaks Gobject-Introspection.

msg110277 - (view)

Author: Éric Araujo (eric.araujo) * (Python committer)

Date: 2010-07-14 13:11

Please produce a test to prove that Python behaves in contradiction to the documentation. Otherwise I’m afraid it’s a GI bug, like in your tests :)

msg110279 - (view)

Author: Ariel Ben-Yehuda (arielbyd)

Date: 2010-07-14 13:20

My test on Class Methods was based on the GI Code that does not run on Python 2.7.

msg110280 - (view)

Author: Éric Araujo (eric.araujo) * (Python committer)

Date: 2010-07-14 13:29

I am afraid we have conflicting viewpoints. You are saying that upgrading Python broke code, and I agree it’s a bad thing. Usually such regression reports are accepted and fixed.

In this case however, the code was already broken in the previous version, it was only working because of a problem in the implementation. So from the viewpoint of GI users, it’s a regression, but from the viewpoint of Python the 2.7 behavior fixes a regression in 2.6. It is not supported to find magic methods (“__name__”) on instances.

msg110281 - (view)

Author: Éric Araujo (eric.araujo) * (Python committer)

Date: 2010-07-14 13:36

Since Benjamin Peterson, release manager for 2.7, confirmed that the change was intentional, I’m closing again.

To solve the bug in GI, you need to define a metaclass with those enter and exit methods, then use it as metaclass for LibtoolImporter. Please send me private email if you want more details.

msg110295 - (view)

Author: Ariel Ben-Yehuda (arielbyd)

Date: 2010-07-14 16:13

Done it for myself. However, I am not a GI Maintainer - you should talk with them and send them this patch.

msg110321 - (view)

Author: Éric Araujo (eric.araujo) * (Python committer)

Date: 2010-07-14 19:40

Since you know the project, the bug and the fix, I think you’re in a better position than me to talk with them.

History

Date

User

Action

Args

2022-04-11 14:57:03

admin

set

github: 53505

2010-07-26 10:11:26

dmalcolm

set

nosy: + dmalcolm

2010-07-14 19:40:39

eric.araujo

set

messages: +

2010-07-14 16:13:46

arielbyd

set

messages: +

2010-07-14 13:36:56

eric.araujo

set

status: open -> closed

messages: +

2010-07-14 13:29:38

eric.araujo

set

messages: +

2010-07-14 13:20:07

arielbyd

set

messages: +

2010-07-14 13:11:00

eric.araujo

set

messages: +

2010-07-14 13:09:29

arielbyd

set

status: closed -> open

messages: +

2010-07-14 13:07:51

eric.araujo

set

status: open -> closed
type: behavior
resolution: not a bug
stage: resolved

2010-07-14 13:07:31

eric.araujo

set

nosy: + eric.araujo
messages: +

2010-07-14 12:02:38

pitrou

set

nosy: + benjamin.peterson

2010-07-14 11:53:15

arielbyd

create