question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

collections.ChainMap not support in Python2

See original GitHub issue

I am using Python 2.7.13, when try to use pysnooper.snoop decorator, meet the AttributeError exception, the reason is collections.ChainMap is used in tracer.py, which is not supported in Python2.x.

code is here: https://github.com/cool-RR/PySnooper/blob/master/pysnooper/tracer.py#L27

hoping PySnooper is fully compatible with python2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
monhzcommented, Apr 24, 2019

from ConfigParser import _Chainmap as ChainMap works fine in 2.7.

2reactions
blargomatcommented, Apr 24, 2019

unfortunately even after upgrading via pip (tested it just now) i still got:

  File "/usr/local/lib/python2.7/dist-packages/pysnooper/tracer.py", line 162, in trace
    get_local_reprs(frame, variables=self.variables)
  File "/usr/local/lib/python2.7/dist-packages/pysnooper/tracer.py", line 28, in get_local_reprs
    locals_and_globals = collections.ChainMap(frame.f_locals, frame.f_globals)
  AttributeError: 'module' object has no attribute 'ChainMap'

however this works in tracer.py but requires the chainmap pip package 😕

locals_and_globals = None
if sys.version_info.major > 2:
    locals_and_globals = collections.ChainMap(frame.f_locals, frame.f_globals)
else:
    from chainmap import ChainMap
    locals_and_globals = ChainMap(frame.f_locals, frame.f_globals)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python's ChainMap: Manage Multiple Contexts Effectively
Python's ChainMap from the collections module provides an efficient tool for managing several dictionaries as a single one. This class is handy when...
Read more >
why can I not import the Chainmap module in python [closed]
I'm using python 3.6 and I have successfully imported from the collections such modules as deque and counter but I cannot import Chainmap....
Read more >
collections — Container datatypes — Python 3.11.1 ...
A ChainMap groups multiple dicts or other mappings together to create a single, updateable view. If no maps are specified, a single empty...
Read more >
Collections ChainMaps in Python: Complete Guide - Datagy
The Python collections module provides Python's implementations of chain maps with the ChainMaps class. This allows you to implement ...
Read more >
ChainMap in Python - GeeksforGeeks
Python contains a container called “ChainMap” which encapsulates many dictionaries into one unit. ChainMap is member of module “collections“ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found