dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.43k stars 59 forks source link

Crash in collect_types _removeHandlerRef #14

Closed jabdoa2 closed 6 years ago

jabdoa2 commented 6 years ago

With the workaround from #13 applied I get this error:

  File "/usr/lib/python3.5/logging/__init__.py", line 725, in _removeHandlerRef
  File "/usr/local/lib/python3.5/dist-packages/pyannotate_runtime/collect_types.py", line 681, in _trace_dispatch
AttributeError: 'NoneType' object has no attribute 'get'

I suppose that the check is slightly broken there. This fixes it for me:

    key = id(code)
    if not sampling_counters: # add this if to prevent the crash
        return
    n = sampling_counters.get(key, 0)
    if n is None:
        return

After this an #13 collection of types works in Python 3.5 on Ubuntu 16.04.

gvanrossum commented 6 years ago

Can you submit a PR?

gvanrossum commented 6 years ago

Is this during Python's global teardown, at the very end of the program? As a workaround, you should call stop_types_collection() before exiting. In the next revision it will be fixed by revision 54d27b4d5e34a3919c31a105f601a59b8a89451c.

jabdoa2 commented 6 years ago

Yes that is during shutdown. It already wrote the annotations to disk. Can probably be closed then.

gvanrossum commented 6 years ago

Great!