cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Python 2 support #2

Closed unformatt closed 2 years ago

unformatt commented 5 years ago

Using 2.7.15. My gut tells me this lib is python3 only but then I wonder why pip was able to install it in my python 2 env.

File "lib/python2.7/site-packages/stackprinter/__init__.py", line 163
    print(format(thing, **kwargs), file=file)
cknd commented 5 years ago

Sorry! I'll add a thing to keep pip from installing on older versions (wouldn't know where to begin to retrofit py2 compatibility, though)

edit: see below!

unformatt commented 5 years ago

Took a couple tweaks to get the past syntax errors and running in python 2. But seems there are a few differences with how tracebacks are inspected in python 2 that make it out of my wheelhouse to figure out but it might not be too hard to get this working in python 2 for someone that knows what they're doing.

unformatt commented 5 years ago

I got this running in python 2 (in django as well). Just hacked it up quickly, so my version no longer works with python 3 but if you look at the changes, it'd be pretty easy to make it work with both python 2 and 3.

https://github.com/unformatt/stackprinter/commit/80858989de8eca281b2ce1409273eccab0eeac42

skorokithakis commented 5 years ago

TBVaccine supports Python 2, btw.

cknd commented 5 years ago

@unformatt After careful deliberation / procrastination, I think I don't want to maintain Python 2 support myself. I'll keep this issue open so people who need it can discover your Py 2 fork

ghost commented 4 years ago

Here is the perspective of someone who tried to get this working with Python 2 and failed:

I believe it's important enough to explicitly state in the README that this is a Python 3 only package, since the README is the first piece of info that a new user gets exposed to. While Python 2 is going to become less and less relevant really soon, it'll be a while till I (and probably some others) will stop instinctively think that if the README of a Python package doesn't explicitly state supported Python versions, then it works with both 2 and 3. In my case I have installed stackprinter through pip, tried to use it in a Python 2 codebase, got it failing and only then checked setup.py, which explicitly states that this is Python 3 only.

As for the fork with Python 2 support, explicitly mentioning it in the README would probably be nice too. And how do I install it? Just

pip install git+https://github.com/unformatt/stackprinter/

? I am noticing that setup.py of the fork still claims Python 3 only is supported, so I suppose that has to be changed too? But I'd be happy to continue the talk about the fork in an issue linked to the fork, not here.

cknd commented 4 years ago

Oy, so pip didn't refuse the installation? I always assumed the python_requires>=3.4 would make it fail earlier & more helpfully in a py 2 environment. I added the notice to the readme now to save others from this particular trap.

zoomlogo commented 3 years ago

Python 2 is deprecated (yes it happened last year). I think this issue should be closed.

cknd commented 3 years ago

https://github.com/cknd/stackprinter/issues/2#issuecomment-489458606