Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to warn about Python 3.x possible incompatibilities #2191

Closed
jedie opened this issue Jan 13, 2017 · 17 comments
Closed

add an option to warn about Python 3.x possible incompatibilities #2191

jedie opened this issue Jan 13, 2017 · 17 comments
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch

Comments

@jedie
Copy link

jedie commented Jan 13, 2017

Is it possible to enable "-3" by default?!?

The Python Interpreter parameter "-3" will warn about Python 3.x possible incompatibilities, see: https://docs.python.org/2/using/cmdline.html#cmdoption-3

Normally i just run pytest
To enable the warnings, i can run via python -3 -m pytest

@RonnyPfannschmidt
Copy link
Member

there will be a path to it after we integrate warnings support

its technically not possible to trigger -3 from entry-points as of now - so unless someone fixes that we simply cannot do

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog labels Jan 13, 2017
@nicoddemus
Copy link
Member

@RonnyPfannschmidt

there will be a path to it after we integrate warnings support

I'm curious, is there a way to programmatically enable -3 by default?

@RonnyPfannschmidt
Copy link
Member

RonnyPfannschmidt commented Jan 13, 2017

@nicoddemus -3 just makes python skip on ignoring certain warnings - that can easily be configured

@nicoddemus
Copy link
Member

that can easily be configured

That was my question, how to do it. 😁 I didn't see how after a quick look at the 2.7's docs.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus uppon investigation, its disturbingly simple because the stdlib has an utterly hacky solution

just set sys.py3kwarning to true

@RonnyPfannschmidt
Copy link
Member

so we could actually support it just as a cli option

@nicoddemus
Copy link
Member

Heh that's interesting.

Yeah simple enough to support. We probably we should add it as an INI option, and users can use the new -o cli option if they want to enable it on the command line. I think most users will want to enable that option permanently on pytest.ini and on CI rather than as a one time shot on the command line (which would still be possible).

@nicoddemus nicoddemus added the good first issue easy issue that is friendly to new contributor label Jan 13, 2017
@RonnyPfannschmidt RonnyPfannschmidt added status: help wanted developers would like help from experts on this topic type: feature-branch new feature or API change, should be merged into features branch and removed type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Jan 13, 2017
@RonnyPfannschmidt RonnyPfannschmidt changed the title Warn about Python 3.x possible incompatibilities add an option to warn about Python 3.x possible incompatibilities Jan 13, 2017
@jedie
Copy link
Author

jedie commented Feb 9, 2017

just set sys.py3kwarning to true

But the docs says:

This should be considered read-only; setting it to a different value doesn’t have an effect on Python 3 warnings.

see: https://docs.python.org/2/library/sys.html#sys.py3kwarning

@nicoddemus
Copy link
Member

I'm not sure that is possible to fix then.

@The-Compiler The-Compiler removed the good first issue easy issue that is friendly to new contributor label Apr 7, 2017
@RonnyPfannschmidt
Copy link
Member

@nicoddemus based on

>>> print inspect.getsource(warnings.warnpy3k)
def warnpy3k(message, category=None, stacklevel=1):
    """Issue a deprecation warning for Python 3.x related changes.

    Warnings are omitted unless Python is started with the -3 option.
    """
    if sys.py3kwarning:
        if category is None:
            category = DeprecationWarning
        warn(message, category, stacklevel+1)

on python 2 it should be possible to just set it and get agood deal out of it

@RonnyPfannschmidt
Copy link
Member

the option should named in a way that signifies we try and hack a readonly var

@RonnyPfannschmidt RonnyPfannschmidt added the good first issue easy issue that is friendly to new contributor label Aug 16, 2017
@rhuard
Copy link

rhuard commented Aug 23, 2017

I was looking around at the help wanted tags for a first contribution. So I started exploring this issue a little bit.

I may be misunderstanding some of this discussion, as I am still not super familiar with the code base. However, I do not believe that setting sys.py3kwarning to True will be sufficient.

I wrote a quick example:

import sys 

class CauseWarning(object): 

    def __eq__(self, other):
        return self._foo == other._foo

if __name__ == '__main__':
    print(sys.py3kwarning)

when run with python2 and no -3 flag one gets:

False

which is expected

when running with the -3 flag one gets:

test_warn.py:6: DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x
  class CauseWarning(object):
True

also expected

However, when you add in the line sys.py3kwarning = True you get:

True

but no warning.

Please let me know if I am missing anything, but with some quick investigations, it appears setting sys.py3kwarning my not be sufficient.

@nicoddemus
Copy link
Member

@rhuard I'm not sure, indeed it doesn't seem to be enough.

To check if this was something that only takes effect if set before importing a module, I also tried to:

py -2 -c "import sys; sys.py3kwarning=1; import foo"

(where foo.py contains your example code)

But this also doesn't produce any warning.

@rhuard
Copy link

rhuard commented Aug 23, 2017

@nicoddemus I was trying something similar with the python interactive interpreter:

entering into interactive with python -3:

+>>> import sys
+>>> sys.py3kwarning = False
+>>> import test_warn
test_warn.py:8: DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x
  class CauseWarning(object)

where test_warn.py is the code spinet I put up earlier. If you start interactive interpreter without the -3 and then set sys.py3kwarning = True, there is no warning. Which is consistent with what we have seen.

Since the docs say py3kwarning is read-only. I am thinking -3 is doing more internally in python than setting a bool. I haven't had time yet today to dig much deeper though.

@nicoddemus
Copy link
Member

I see @rhuard, thanks for confirming. 👍

@RonnyPfannschmidt
Copy link
Member

it seems we cant fix the python internals

will close this one as wontfix

@RonnyPfannschmidt
Copy link
Member

@rhuard thanks for confirming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

5 participants