Skip to content

Drop py27 and py34 support #5318

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

Merged
merged 1 commit into from
Jun 2, 2019
Merged

Conversation

nicoddemus
Copy link
Member

@nicoddemus nicoddemus commented May 27, 2019

Related to #5275

@nicoddemus nicoddemus changed the title [WIP] Drop py27 py34 [WIP] Drop py27 and py34 support May 27, 2019
@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #5318 into master will increase coverage by 0.99%.
The diff coverage is 98.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5318      +/-   ##
==========================================
+ Coverage   93.43%   94.43%   +0.99%     
==========================================
  Files         115      115              
  Lines       26399    25895     -504     
  Branches     2606     2496     -110     
==========================================
- Hits        24667    24453     -214     
+ Misses       1409     1126     -283     
+ Partials      323      316       -7
Impacted Files Coverage Δ
testing/test_warnings.py 61.21% <ø> (+12.03%) ⬆️
src/_pytest/assertion/__init__.py 89.55% <ø> (+2.59%) ⬆️
src/_pytest/doctest.py 95.5% <ø> (-0.93%) ⬇️
src/_pytest/recwarn.py 98.09% <ø> (-0.3%) ⬇️
testing/python/metafunc.py 93.55% <ø> (+6.75%) ⬆️
testing/test_compat.py 100% <ø> (ø) ⬆️
src/_pytest/warnings.py 87.32% <ø> (-1.57%) ⬇️
testing/test_config.py 99.82% <ø> (ø) ⬆️
src/_pytest/junitxml.py 95.88% <ø> (-0.03%) ⬇️
testing/test_tmpdir.py 98.36% <ø> (-0.57%) ⬇️
... and 76 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 733f43b...4d49ba6. Read the comment docs.

@nicoddemus
Copy link
Member Author

Oh coverage will drop quite a bit because of dead Python 2 code (which we should tackle in future PRs).

blueyed
blueyed previously approved these changes May 28, 2019
@blueyed
Copy link
Contributor

blueyed commented May 28, 2019

which we should tackle in future PRs

Why not here?
We have the coverage indicator here, but not later anymore.

@nicoddemus
Copy link
Member Author

Why not here?
We have the coverage indicator here, but not later anymore.

Fair enough. I will get to this tomorrow or after 4.6 gets out. 👍

@blueyed
Copy link
Contributor

blueyed commented May 28, 2019

Pushed a minor commit removing one instance/import of six - it should get removed completely (added a TODO).

@asottile
Copy link
Member

pyupgrade will handle that @blueyed -- no need to make those changes here

@blueyed
Copy link
Contributor

blueyed commented May 28, 2019

@asottile
Ah, sure - should be run here then already, no?

@asottile
Copy link
Member

it was my understanding from #5275 that we were going to do that in two separate branches (this one, and then I'd follow up with a separate pyupgrade branch)

@blueyed
Copy link
Contributor

blueyed commented May 28, 2019

It would help / is required for the coverage - otherwise you would have to compare this "manually" from before this PR and after the pyupgrade one.
I think it is good to have this all in one place.

@asottile
Copy link
Member

🤷‍♂️ I don't think the coverage number matters too much -- I'd prefer two separate PRs personally

@nicoddemus
Copy link
Member Author

About the two separate PRs:

One problem with just pushing manual + automatic changes in the same PR is that it makes it difficult to review the manual changes. I'm sure if we had just pushed the changes we have here in addition to automatic changes introduced by pyupgrade, the comments made here might not have been made at all among all the noise. On the other hand, I understand @blueyed's sentiment about having a clear place to check for the absolute coverage.

Having said that, how about:

  1. We keep the scope of the PR as it is now, only the manual changes I've made + removing the if six.P* blocks. I plan to finish this today.
  2. Once this is done, people should request further changes and finally approve it.
  3. Once everyone has approved this, instead of merging it, @asottile then pushes the automatic changes to this PR.
  4. Everybody now has a chance of requesting further changes until we finally merge it (after 4.6 is out of course).

This might seem complicated at first sight, but is in essence just "approve it now what you see, later we will push more changes before merging".

What do you guys think?

@asottile
Copy link
Member

We keep the scope of the PR as it is now, only the manual changes I've made + removing the if six.P* blocks. I plan to finish this today.

pyupgrade is about to support this as well, mostly done :) asottile/pyupgrade#153

@nicoddemus
Copy link
Member Author

pyupgrade is about to support this as well, mostly done :) asottile/pyupgrade#153

Cool!

I will do it myself later anyway, a few of places are not straightforward to remove cleanly.

Some examples:

if six.PY2:
def _max(iterable, default):
"""needed due to python2.7 lacking the default argument for max"""
return reduce(max, iterable, default)
else:
_max = max

Here it makes sense to use max directly instead of _max, assuming pyupgrade will keep just _max = max.

def _attempt_to_close_capture_file(f):
"""Suppress IOError when closing the temporary file used for capturing streams in py27 (#2370)"""
if six.PY2:
try:
f.close()
except IOError:
pass
else:
f.close()

Here it makes sense to also remove _attempt_to_close_capture_file and call f.close() directly instead.

Also there are tests which are Python 2 only which should be removed completely.

There other exmaples, although most would be handled by pyupgrade just fine. 😁

@nicoddemus
Copy link
Member Author

OK, removed everything I could find that was related to Python 2 in the code: code blocks with sys.version_info, six.PY2, six.PY3, _pytest.compat functions no longer necessary, etc. 😅

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, feel free to ignore the issue -- we can always follow up with another round of cleanup afterwards :)

I'm going to wait to pyupgrade this until we release 4.6 so we can rebase on top of that

else:
e = None
repr_chain.reverse()
return ExceptionChainRepr(repr_chain)


class TerminalRepr(object):
def __str__(self):
s = self.__unicode__()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v minor, we should be able to get rid of __unicode__ for __str__

@nicoddemus
Copy link
Member Author

v minor, we should be able to get rid of unicode for str

Good catch, missed it. I will get to this later.

@nicoddemus
Copy link
Member Author

I'm going to wait to pyupgrade this until we release 4.6 so we can rebase on top of that

Yes, I was going to suggest that. We should do that right before merging this PR, after 4.6 is out. 👍

@blueyed blueyed requested review from blueyed and removed request for blueyed May 29, 2019 22:21
Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work. just need re-base I guess

@nicoddemus nicoddemus changed the base branch from features to master June 2, 2019 14:45
@nicoddemus
Copy link
Member Author

Rebased/squased into master: we have already created the 4.6-maintenance branch, so this can go directly to master.

Also I think we can run pyupgrade in a separate PR, as it should not affect coverage at all.

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so happy to see all these hacks disappear!

@nicoddemus nicoddemus changed the title [WIP] Drop py27 and py34 support Drop py27 and py34 support Jun 2, 2019
@asottile
Copy link
Member

asottile commented Jun 2, 2019

sweet, let's get this into master :D

@nicoddemus nicoddemus force-pushed the drop-py27-py34 branch 2 times, most recently from 9cd23ab to e90534d Compare June 2, 2019 15:57

if _PY3:

def safe_str(v):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noted this one is evil, looking at usage sites made me think the removal was bad in some case

Copy link
Member Author

@nicoddemus nicoddemus Jun 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean @RonnyPfannschmidt? The Python 3 version was just calling str(), so I changed the call sites to call str() as well and removed the safe_str function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoddemus the function name was terrible for indicating the actual intent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK.

Could you please "accept" the PR once you finished the review? It would be nice to get this into master soon.

* Update setup.py requires and classifiers
* Drop Python 2.7 and 3.4 from CI
* Update docs dropping 2.7 and 3.4 support
* Fix mock imports and remove tests related to pypi's mock module
* Add py27 and 34 support docs to the sidebar
* Remove usage of six from tmpdir
* Remove six.PY* code blocks
* Remove sys.version_info related code
* Cleanup compat
* Remove obsolete safe_str
* Remove obsolete __unicode__ methods
* Remove compat.PY35 and compat.PY36: not really needed anymore
* Remove unused UNICODE_TYPES
* Remove Jython specific code
* Remove some Python 2 references from docs

Related to pytest-dev#5275
@nicoddemus nicoddemus merged commit 602a290 into pytest-dev:master Jun 2, 2019
@nicoddemus nicoddemus deleted the drop-py27-py34 branch June 2, 2019 22:14
@nicoddemus
Copy link
Member Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants