itamarst / eliot

Eliot: the logging system that tells you *why* it happened
https://eliot.readthedocs.io
Apache License 2.0
1.1k stars 66 forks source link

boltons bug causing NameError when you @log_call a function with typing.Tuple #362

Closed guy4261 closed 5 years ago

guy4261 commented 5 years ago

When I decorate a function call in which types are defined using typing.Tuple, I get a NameError from somewhere deep inside the boltons library. Although it's their bug, I thought you should know. I'd try to follow-up with them as well.

# bug.py
from typing import Tuple
from eliot import log_call

@log_call
def length(x: Tuple) -> int:
    return len(x)

length((1, 2, 3))

On Python 3.6.7, running $ python bug.py results in:

Traceback (most recent call last):
  File "bug.py", line 7, in <module>
    def length(x: Tuple) -> int:
  File "/Users/grapaport/hemi36/lib/python3.6/site-packages/eliot/_action.py", line 914, in log_call
    @wraps(wrapped_function)
  File "/Users/grapaport/hemi36/lib/python3.6/site-packages/boltons/funcutils.py", line 327, in wrapper_wrapper
    fully_wrapped = fb.get_func(execdict, with_dict=update_dict)
  File "/Users/grapaport/hemi36/lib/python3.6/site-packages/boltons/funcutils.py", line 591, in get_func
    self._compile(src, execdict)
  File "/Users/grapaport/hemi36/lib/python3.6/site-packages/boltons/funcutils.py", line 679, in _compile
    exec(code, execdict)
  File "<boltons.funcutils.FunctionBuilder-0>", line 1, in <module>
NameError: name 'Tuple' is not defined
itamarst commented 5 years ago

:(

As a workaround you can probably do:

import typing
import boltons.funcutils
bolton.funcutils.Tuple = typing.Tuple
itamarst commented 5 years ago

Or, wait. That might be a more exciting bug than it looks like.

itamarst commented 5 years ago

An actual plausible workaround—before importing eliot do:

import boltons.funcutils
import functools
boltons.funcutils.wraps = functools.wraps
guy4261 commented 5 years ago

Thanks! Just went over the boltons issues and saw you were already there a minute ago! 🙇

itamarst commented 5 years ago

Sorry this change broke things for you :( If I don't see a fix to boltons soon I'll do another release where I remove it.

Incidentally, may I ask what you're using Eliot for?

guy4261 commented 5 years ago

I'm rewriting a big fat data pipeline I created a long time ago and I thought that was a good opportunity to give Eliot a try†. I don't want to spin up a big fancy logging system (e.g. ELK/Splunk) and Eliot sounds like a good balance between simple and smart.

† This is something I wanted to do since I enlisted on Software Clown††. †† This is not a paid comment!

itamarst commented 5 years ago

Cool, let me know if you have any other problems! (Working on the boltons issue.)

itamarst commented 5 years ago

OK, there's new boltons 19.0.1 release that should fix this, but I'll try to do a new Eliot release that enforces that as a minimum dependency.

guy4261 commented 5 years ago
$ pip install -U boltons
$ pip list | grep boltons
boltons            19.0.1
$ python bug.py

All is well! I don't know if the new version impacts anything else (i.e., if you should update eliot's requirements.txt already or not) but this behavior no longer appears! Thanks!!!