Opened 16 years ago

Closed 14 years ago

#1876 enhancement closed invalid (invalid)

IReactorTime.callLater masks the builtin 'callable' in its arglist

Reported by: Stephen Thorne Owned by:
Priority: low Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

Inconsistency found when reviewing code in 1875, 'callable' is a python builtin, and we mask it in the arg list in places like IReactorTime.callLater and friends.

$ egrep "^(    )?def.*callable" *
base.py:    def callWhenRunning(self, _callable, *args, **kw):
defer.py:def execute(callable, *args, **kw):
interfaces.py:    def callLater(self, delay, callable, *args, **kw):
interfaces.py:    def callInThread(self, callable, *args, **kwargs):
interfaces.py:    def callFromThread(self, callable, *args, **kw):
interfaces.py:    def addSystemEventTrigger(self, phase, eventType, callable, *args, **kw):
interfaces.py:    def callWhenRunning(self, callable, *args, **kw):

It would be nice if we did not assign to builtins in twisted code.

(set to low priority, this is a code cleanliness issue)

Change History (5)

comment:1 Changed 16 years ago by Jean-Paul Calderone

It is basically totally irrelevant that the builtin callable is masked by these functions.

What could be an issue, but as far as I can tell never actually has been, is that these functions prevent you from passing certain keywords through to the target callable: self, delay, callable, etc, cannot be passed as keyword args. I doubt this is worth fixing, since it has never been a practical problem. Most people use positional arguments most of the time anyway.

comment:2 Changed 16 years ago by jknight

If that's an issue, the following little trick might come in handy:

>>> def foo((a), (b), **kwargs):
...  print a, b, kwargs
... 
>>> foo(1, 2)
1 2 {}
>>> foo(a=1, b=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: foo() takes exactly 2 non-keyword arguments (0 given)
>>> foo(3, 4, a=1, b=2)
3 4 {'a': 1, 'b': 2}

comment:3 Changed 15 years ago by Jean-Paul Calderone

Wow, that's a crazy trick. There are a few other places in Twisted which jump through *a and kw hoops which would be simplified by this.

Alas:

Python 2.5 (release25-maint:53197, Dec 29 2006, 21:33:35)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f((a), (b), **c):
...     print a, b, c
...
>>> f(a=10, b=20)
10 20 {}
>>>

comment:4 Changed 14 years ago by Jean-Paul Calderone

Resolution: invalid
Status: newclosed

Non-issue.

comment:5 Changed 11 years ago by <automation>

Owner: Glyph deleted
Note: See TracTickets for help on using tickets.