Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE Shell: delattr(__builtins__,"getattr") causes shell to stop working #59318

Closed
RamchandraApte mannequin opened this issue Jun 20, 2012 · 9 comments
Closed

IDLE Shell: delattr(__builtins__,"getattr") causes shell to stop working #59318

RamchandraApte mannequin opened this issue Jun 20, 2012 · 9 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@RamchandraApte
Copy link
Mannequin

RamchandraApte mannequin commented Jun 20, 2012

BPO 15113
Nosy @loewis, @terryjreedy, @amauryfa, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-06-20.14:03:06.258>
created_at = <Date 2012-06-20.06:03:51.492>
labels = ['type-bug', 'invalid']
title = 'IDLE Shell: delattr(__builtins__,"getattr") causes shell to stop working'
updated_at = <Date 2012-06-20.18:36:34.988>
user = 'https://bugs.python.org/RamchandraApte'

bugs.python.org fields:

activity = <Date 2012-06-20.18:36:34.988>
actor = 'terry.reedy'
assignee = 'none'
closed = True
closed_date = <Date 2012-06-20.14:03:06.258>
closer = 'r.david.murray'
components = []
creation = <Date 2012-06-20.06:03:51.492>
creator = 'Ramchandra Apte'
dependencies = []
files = []
hgrepos = []
issue_num = 15113
keywords = []
message_count = 9.0
messages = ['163254', '163255', '163256', '163257', '163267', '163268', '163271', '163272', '163290']
nosy_count = 5.0
nosy_names = ['loewis', 'terry.reedy', 'amaury.forgeotdarc', 'r.david.murray', 'Ramchandra Apte']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue15113'
versions = ['Python 3.2']

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jun 20, 2012

delattr(builtins,"getattr") causes shell to stop working
if you type some code in nothing gets printed back
if you press enter without typing any code you get a traceback

Exception in thread SockThread:
Traceback (most recent call last):
  File "/usr/lib/python3.2/socketserver.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.2/socketserver.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.2/socketserver.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.2/idlelib/rpc.py", line 503, in __init__
    socketserver.BaseRequestHandler.__init__(self, sock, addr, svr)
  File "/usr/lib/python3.2/socketserver.py", line 637, in __init__
    self.handle()
  File "/usr/lib/python3.2/idlelib/run.py", line 264, in handle
    rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
  File "/usr/lib/python3.2/idlelib/rpc.py", line 280, in getresponse
    response = self._getresponse(myseq, wait)
  File "/usr/lib/python3.2/idlelib/rpc.py", line 300, in _getresponse
    response = self.pollresponse(myseq, wait)
  File "/usr/lib/python3.2/idlelib/rpc.py", line 438, in pollresponse
    response = self.localcall(seq, resq)
  File "/usr/lib/python3.2/idlelib/rpc.py", line 185, in localcall
    method = getattr(obj, methodname)
NameError: global name 'getattr' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.2/idlelib/run.py", line 135, in manage_socket
    server.handle_request() # A single request only
  File "/usr/lib/python3.2/socketserver.py", line 269, in handle_request
    self._handle_request_noblock()
  File "/usr/lib/python3.2/socketserver.py", line 286, in _handle_request_noblock
    self.handle_error(request, client_address)
  File "/usr/lib/python3.2/idlelib/run.py", line 240, in handle_error
    print('Request: ', repr(request), file=erf)
  File "/usr/lib/python3.2/socket.py", line 111, in __repr__
    getattr(self, '_closed', False) and " [closed] " or "",
NameError: global name 'getattr' is not defined

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jun 20, 2012

Running the delattr(builtins,"getattr") in Python from the cmd line doesn't create any problems though.

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jun 20, 2012

Another note: this bug is reproducable in the IDLE Shell with the python subprocess feature enabled (the python process that runs your commands and the python process that manages IDLE's windows are different).

@loewis
Copy link
Mannequin

loewis mannequin commented Jun 20, 2012

Why do you think this is a bug? It is expected behavior.

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jun 20, 2012

IDLE should try to mimic Python as much as feasible.

@RamchandraApte
Copy link
Mannequin Author

RamchandraApte mannequin commented Jun 20, 2012

s/Python/Python in cmd

@bitdancer
Copy link
Member

Well, I don't think that imitating the command line needs to extend to supporting doing unusual things to builtins, so unless someone like Terry disagrees I think we should close this as won't fix.

@bitdancer bitdancer added the type-bug An unexpected behavior, bug, or error label Jun 20, 2012
@amauryfa
Copy link
Member

I'm afraid it's not feasible. Python (or IDLE) is allowed to rely on Python working correctly, and if commonly used functions are modified there will be unexpected errors.

Likewise in 3.3, after a "del __builtins__.hasattr", even import statements will fail...

@terryjreedy
Copy link
Member

To put it another way, IDLE is written for standard Python. A standard Python interpreter has a getattr builtin that works as documented in the library manual. Deleting that or any other builtin makes the interpreter non-standard. So would replacing or wrapping the builtin with a function that does anything other than innocuously augmenting the behavior with something like counting calls or logging them to a file.

Deletion of getattr *does* create problems for CPython (or any interpreter) in that legal Python code using getattr no longer runs. I presume CPython can limp along and execute other code because it directly calls the C function wrapped by the __builtins__.getattr object.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants