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

Drop support for Python 3.7 #10009

Merged
merged 3 commits into from
May 5, 2023
Merged

Drop support for Python 3.7 #10009

merged 3 commits into from
May 5, 2023

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Apr 21, 2023

Summary

This updates our documentation and build processes to set Python 3.8 as the oldest support version of Python, consistent with our policy on Python support.

This commit also removes remaining Python-version gating, since we were principally using this to account for differences between 3.7 and 3.8. Several backport packages are no longer required for any suppported Python version, because of this change.

Details and comments

New niceties that are now valid for inclusion in Terra:

  • assignment expressions using := (the walrus operator). Use these sparingly; it's easy to write illegible code with them that technically passes the style check. The archetypal clean usage of it is for checking a variable that's created and only used within the if branch, like

    if (obj_attribute := getattr(obj, "attribute", None)) is not None:
        # ... do something with 'obj_attribute'
  • positional-only parameters in functions. These arguments cannot be passed as keyword arguments. When there's no reason that an argument should be passed as a keyword at all, it's a good idea to use this, because it means that the name of that variable isn't leaked into the public API, so changing its name doesn't need any deprecations (for example if the accepted types / objects are going to expand, and the original name doesn't make sense any more).

    You can also use positional-only keyword arguments to allow a function that takes **kwargs to accept any name:

    def f(a, /):
        return a
    f(1)    # 1
    f(a=1)  # TypeError: f() got some positional-only arguments passed as keyword arguments: 'a'
    
    def f(a, /, **kwargs):
        return a, kwargs
    f(1)       # 1, {}
    f(1, a=2)  # 1, {"a": 2}

    The Python 3.8+ standard library uses lots of these, as do extension modules. They're often a good idea.

  • Lots of parts of the typing module are now available without needing the backport typing_extensions

  • importlib.metadata is available without its backport importlib_metadata

  • Two additions to functools are now stabilised (cached_property and singledispatchmethod) (and lru_cache no longer needs a maxsize explicitly setting)

  • multiprocessing.shared_memory is now available.

@jakelishman jakelishman added the Changelog: API Change Include in the "Changed" section of the changelog label Apr 21, 2023
@jakelishman jakelishman added this to the 0.25.0 milestone Apr 21, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

This updates our documentation and build processes to set Python 3.8 as
the oldest support version of Python, consistent with our policy on
Python support.

This commit also removes remaining Python-version gating, since we were
principally using this to account for differences between 3.7 and 3.8.
Several backport packages are no longer required for any suppported
Python version, because of this change.
@mtreinish
Copy link
Member

Heh, we've entered the domain where no supported version of python will run multiprocessing on macOS by default, and that's causing a test to fail: https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=45813&view=logs&j=80763036-ed5e-5d3e-143d-8ae8edc29f03&t=0b590cc4-1220-55fc-f610-714bdf68abc8&l=23469

With Python 3.7 support now dropped, there are no versions of Python on
macOS that we expect to support with multiprocessing again.  There's no
guarantee that the hypothetical Python 10.11 (???) that this test was
previously checking would be any more valid than existing versions.
@jakelishman
Copy link
Member Author

Yeah, that test was testing that we said we'd support Python 10.11?? Pretty odd. I've removed the test in 1140a03.

@mtreinish
Copy link
Member

Just out of curiosity I ran pupgrade --plus-38 on the repo. It changed ~300 lines. I think all of the changes were to type hints though, basically dropping quotes on non-imported types and changing things like Union[int, flow] to int | float and Optional[int] to int | None. We probably should look into whether we want to make those changes in a follow up PR

@jakelishman
Copy link
Member Author

Yeah, I just tried that. A bunch of its changes actually look not totally related to Python 3.8 - there's a lot of stuff like removing quotes from delayed annotations in files that already have from __future__ import annotations that are fine. It seems to go beyond its remit, though - it's done a bunch of removing unnecessary tuples from calls to all. It's not wrong, but that's not a change enabled by Python 3.8 (and the way it's done it violates black, but that's easy to fix). Let's look at it in a follow-up.

@coveralls
Copy link

coveralls commented Apr 21, 2023

Pull Request Test Coverage Report for Build 4894490478

  • 13 of 15 (86.67%) changed or added relevant lines in 13 files are covered.
  • 24 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.03%) to 85.832%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/algorithms/optimizers/p_bfgs.py 0 2 0.0%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 90.46%
qiskit/extensions/quantum_initializer/squ.py 2 80.0%
crates/qasm2/src/lex.rs 3 90.38%
crates/accelerate/src/sabre_swap/layer.rs 4 97.32%
crates/qasm2/src/parse.rs 6 97.11%
crates/accelerate/src/vf2_layout.rs 8 86.44%
Totals Coverage Status
Change from base Build 4876894924: -0.03%
Covered Lines: 70785
Relevant Lines: 82469

💛 - Coveralls

mtreinish
mtreinish previously approved these changes Apr 21, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, thanks for doing this. I think we should probably hold off on merging this until after the final 0.24.0 release though, just in case there is a potential version issue during the 2 weeks of overlap while we're developing for both releases at the same time.

@jakelishman
Copy link
Member Author

I'm fine doing that, although technically we're developing 0.24 throughout its entire lifecycle, so there'd still be overlap. There is more risk during the rc period, though, for sure.

@mtreinish mtreinish added the on hold Can not fix yet label Apr 21, 2023
@mtreinish mtreinish removed the on hold Can not fix yet label May 5, 2023
@mtreinish mtreinish enabled auto-merge May 5, 2023 14:29
@mtreinish mtreinish added this pull request to the merge queue May 5, 2023
Merged via the queue into Qiskit:main with commit 4dfef13 May 5, 2023
@jakelishman jakelishman deleted the drop-py37 branch May 16, 2023 10:06
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this pull request May 22, 2023
* Drop support for Python 3.7

This updates our documentation and build processes to set Python 3.8 as
the oldest support version of Python, consistent with our policy on
Python support.

This commit also removes remaining Python-version gating, since we were
principally using this to account for differences between 3.7 and 3.8.
Several backport packages are no longer required for any suppported
Python version, because of this change.

* Remove test for multiprocessing on Mac

With Python 3.7 support now dropped, there are no versions of Python on
macOS that we expect to support with multiprocessing again.  There's no
guarantee that the hypothetical Python 10.11 (???) that this test was
previously checking would be any more valid than existing versions.

---------

Co-authored-by: Matthew Treinish <[email protected]>
ElePT pushed a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
* Drop support for Python 3.7

This updates our documentation and build processes to set Python 3.8 as
the oldest support version of Python, consistent with our policy on
Python support.

This commit also removes remaining Python-version gating, since we were
principally using this to account for differences between 3.7 and 3.8.
Several backport packages are no longer required for any suppported
Python version, because of this change.

* Remove test for multiprocessing on Mac

With Python 3.7 support now dropped, there are no versions of Python on
macOS that we expect to support with multiprocessing again.  There's no
guarantee that the hypothetical Python 10.11 (???) that this test was
previously checking would be any more valid than existing versions.

---------

Co-authored-by: Matthew Treinish <[email protected]>
ElePT pushed a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
* Drop support for Python 3.7

This updates our documentation and build processes to set Python 3.8 as
the oldest support version of Python, consistent with our policy on
Python support.

This commit also removes remaining Python-version gating, since we were
principally using this to account for differences between 3.7 and 3.8.
Several backport packages are no longer required for any suppported
Python version, because of this change.

* Remove test for multiprocessing on Mac

With Python 3.7 support now dropped, there are no versions of Python on
macOS that we expect to support with multiprocessing again.  There's no
guarantee that the hypothetical Python 10.11 (???) that this test was
previously checking would be any more valid than existing versions.

---------

Co-authored-by: Matthew Treinish <[email protected]>
ElePT pushed a commit to ElePT/qiskit-algorithms that referenced this pull request Jul 27, 2023
* Drop support for Python 3.7

This updates our documentation and build processes to set Python 3.8 as
the oldest support version of Python, consistent with our policy on
Python support.

This commit also removes remaining Python-version gating, since we were
principally using this to account for differences between 3.7 and 3.8.
Several backport packages are no longer required for any suppported
Python version, because of this change.

* Remove test for multiprocessing on Mac

With Python 3.7 support now dropped, there are no versions of Python on
macOS that we expect to support with multiprocessing again.  There's no
guarantee that the hypothetical Python 10.11 (???) that this test was
previously checking would be any more valid than existing versions.

---------

Co-authored-by: Matthew Treinish <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants