Github user JoshRosen commented on the pull request:
https://github.com/apache/spark/pull/1623#issuecomment-51024991
I found another technique that may be more robust to `namedtuple` being
accessible under different names. We can replace `namedtuple`'s code object at
runtime in order to interpose on calls to it:
```python
import types
def copy_func(f, name=None): # See
http://stackoverflow.com/a/6528148/590203
return types.FunctionType(f.func_code, f.func_globals, name or
f.func_name,
f.func_defaults, f.func_closure)
from collections import namedtuple
namedtuple._old_namedtuple = copy_func(namedtuple)
def wrapped(*args, **kwargs):
print "Called the wrapped function!"
return namedtuple._old_namedtuple(*args, **kwargs)
namedtuple.func_code = wrapped.func_code
print namedtuple("Person", "name age")
```
This prints
```
Called the wrapped function!
<class 'collections.Person'>
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]