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月11日 17:53 by michael.mulich, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg151072 - (view) | Author: Michael Mulich (michael.mulich) * | Date: 2012年01月11日 17:53 | |
While working on porting wsgi_intercept to Python 3 I came across a recursion issue with http.client.HTTPSConnection. The following is an lesser extraction of the traceback: Traceback (most recent call last): File ".../wsgi_intercept/test/test_httplib.py", line 28, in test_success http = self.make_one(self.domain) File ".../wsgi_intercept/test/test_httplib.py", line 40, in make_one return http.client.HTTPSConnection(*args) File ".../lib/python3.2/http/client.py", line 1075, in __init__ source_address) ... File ".../lib/python3.2/http/client.py", line 1075, in __init__ source_address) File ".../lib/python3.2/http/client.py", line 1074, in __init__ super(HTTPSConnection, self).__init__(host, port, strict, timeout, RuntimeError: maximum recursion depth exceeded while calling a Python object Some background information is necessary to explain what is happening here. One, this is a traceback from a test method (make_one) which makes and https connection. Two, wsgi_intercept has overridden http.client.HTTPSConnection with a class that subclasses HTTPSConnection and overrides a few methonds. For more general information, see the PyPI page (http://pypi.python.org/pypi/wsgi_intercept). After the wsgi_intercept behavior is invoked the __mro__ of http.client.HTTPSConnection becomes: (<class 'wsgi_intercept.WSGI_HTTPSConnection'>, <class 'http.client.HTTPSConnection'>, <class 'http.client.HTTPConnection'>, <class 'object'>). Because of this we end up recursively running the __init__. Possible solutions: 1) Fix the issue in http/client.py:1074 by replacing "super(HTTPSConnection, self)" with "super()", which if I'm not mistaken is the recommended usage of super in Python 3. 2) Fix the issue in the wsgi_intercept package. I was successful with both approaches, but applying the second fix would make the maintenance of wsgi_intercept slightly harder because of the code duplication and round-about-way of calling its parent classes. |
|||
| msg152520 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年02月03日 14:41 | |
Hi, > wsgi_intercept has overridden http.client.HTTPSConnection with a class that subclasses > HTTPSConnection and overrides a few methonds. Do you mean that the module is monkey-patched? > Fix the issue in http/client.py:1074 by replacing "super(HTTPSConnection, self)" with > "super()", which if I'm not mistaken is the recommended usage of super in Python 3. Because it’s possible does not mean it’s liked :) Some of us still dislike that hack. |
|||
| msg152653 - (view) | Author: Michael Mulich (michael.mulich) * | Date: 2012年02月05日 01:13 | |
Sure does. But that's the point of the package. Why is this super usage without arguments considered a hack? > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue13771> > _______________________________________ |
|||
| msg152668 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年02月05日 09:57 | |
super without arguments literally relies on a compiler hack. |
|||
| msg267259 - (view) | Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) | Date: 2016年06月04日 15:56 | |
Could you provide a minimal code sample that demonstrates the problem? I'm having a hard time seeing why the http.client code is buggy. |
|||
| msg267359 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2016年06月05日 01:15 | |
My guess is Michael was doing something like
>>> class Monkey(http.client.HTTPSConnection):
... pass
...
>>> http.client.HTTPSConnection = Monkey
>>> http.client.HTTPSConnection("bugs.python.org")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/http/client.py", line 1210, in __init__
source_address)
[. . .]
File "/usr/lib/python3.5/http/client.py", line 1210, in __init__
source_address)
File "/usr/lib/python3.5/http/client.py", line 1209, in __init__
super(HTTPSConnection, self).__init__(host, port, timeout,
RecursionError: maximum recursion depth exceeded while calling a Python object
Looking at <https://github.com/cdent/wsgi-intercept/commit/d70dfa9>, I think this problem has been overcome by also overriding __init__(). IMO Python shouldn’t go very far out of its way to support monkey patching, and in this case the workaround was disliked by Eric. Given these two facts and no apparent interest since, I think we should close this.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:25 | admin | set | github: 57980 |
| 2016年06月05日 02:32:09 | berker.peksag | set | status: open -> closed resolution: rejected stage: resolved |
| 2016年06月05日 01:15:43 | martin.panter | set | nosy:
+ martin.panter messages: + msg267359 |
| 2016年06月04日 15:56:31 | JelleZijlstra | set | nosy:
+ JelleZijlstra messages: + msg267259 |
| 2012年02月05日 09:57:54 | eric.araujo | set | messages: + msg152668 |
| 2012年02月05日 01:13:22 | michael.mulich | set | messages: + msg152653 |
| 2012年02月03日 14:41:18 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg152520 |
| 2012年01月11日 18:03:00 | pitrou | set | nosy:
+ orsenthil components: + Library (Lib), - None versions: - Python 3.4 |
| 2012年01月11日 17:53:10 | michael.mulich | create | |