From 46bfb354881c74c57fab4f9d7c21f31212c08cda Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 27 Feb 2023 08:21:41 +0100 Subject: [PATCH] drop support for Python 3.9 --- .github/workflows/autofix.yml | 17 +++++++++-------- .github/workflows/main.yml | 2 -- CHANGELOG.md | 1 + CONTRIBUTING.md | 3 +-- docs/scripts/api-events.py | 13 ++++--------- docs/src/content/overview-installation.md | 2 +- mitmproxy/master.py | 5 +---- mitmproxy/utils/signals.py | 6 +----- setup.py | 3 +-- 9 files changed, 19 insertions(+), 33 deletions(-) diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index 00418de7e..2e5f5316a 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -15,30 +15,31 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: install-pinned/pyupgrade@423622e7c2088eeba495a591385ec22074284f90 + - uses: install-pinned/pyupgrade@28e8d2633f6f1a03d5b4709682ce155a66324e6a - name: Run pyupgrade run: | shopt -s globstar export GLOBIGNORE='mitmproxy/contrib/**' - pyupgrade --exit-zero-even-if-changed --keep-runtime-typing --py39-plus **/*.py + pyupgrade --exit-zero-even-if-changed --keep-runtime-typing --py310-plus **/*.py - - uses: install-pinned/reorder_python_imports@946c8bbd8fe048a3bee76063c90c938d5a59a9aa + - uses: install-pinned/reorder_python_imports@2cc264e0f6bc33907796602661e5b26d8199314d - name: Run reorder-python-imports run: | shopt -s globstar export GLOBIGNORE='mitmproxy/contrib/**' - reorder-python-imports --exit-zero-even-if-changed --py39-plus **/*.py - - uses: install-pinned/yesqa@4af1e53e86a56db346a03ece9e89c19bfd0e5d0e + reorder-python-imports --exit-zero-even-if-changed --py310-plus **/*.py + - uses: install-pinned/yesqa@4896f663e9c294fddfbf5f4e4fc4f9b1a4556658 - name: Run yesqa run: | shopt -s globstar export GLOBIGNORE='mitmproxy/contrib/**' yesqa **/*.py || true - - uses: install-pinned/autoflake@19ecc14a8688d57cca9dc6cfd705f16f200ff097 - - run: autoflake --in-place --remove-all-unused-imports --exclude contrib -r . - - uses: install-pinned/black@13c8a20eb904ba800c87f0b34ccfd932ac2ff81d + - uses: install-pinned/autoflake@dfa39c5f136f5b885c175734a719dc6ad1f11fc7 + - run: autoflake --in-place --remove-all-unused-imports --exclude mitmproxy/contrib -r . + + - uses: install-pinned/black@3375665f712256be11c3212db472c3dafc217fa1 - run: black --extend-exclude mitmproxy/contrib . - uses: mhils/add-pr-ref-in-changelog@main diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ebca4893..514d62ee8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,8 +49,6 @@ jobs: py: "3.11" - os: ubuntu-latest py: "3.10" - - os: ubuntu-latest - py: "3.9" runs-on: ${{ matrix.os }} steps: - run: printenv diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f330a4d1..5543af0e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased: mitmproxy next +* mitmproxy now requires Python 3.10 or above. * Fix a bug where the direction indicator in the message stream view would be in the wrong direction. ([#5921](https://github.com/mitmproxy/mitmproxy/issues/5921), @konradh) * Fix a bug where peername would be None in tls_passthrough script, which would make it not working. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f0496090..8541833f0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,8 +14,7 @@ forward, please consider contributing in the following areas: ## Development Setup -To get started hacking on mitmproxy, please install a recent version of Python (we require at least Python 3.9). -Then, do the following: +To get started hacking on mitmproxy, please install the latest version of Python and do the following: ##### Linux / macOS diff --git a/docs/scripts/api-events.py b/docs/scripts/api-events.py index 8f3a72e72..8e7007639 100644 --- a/docs/scripts/api-events.py +++ b/docs/scripts/api-events.py @@ -2,6 +2,7 @@ import contextlib import inspect import textwrap +import typing from pathlib import Path from mitmproxy import addonmanager @@ -33,15 +34,9 @@ def category(name: str, desc: str, hooks: list[type[hooks.Hook]]) -> None: for params in all_params: for param in params: try: - mod = inspect.getmodule(param.annotation).__name__ - if mod == "typing": - # this is ugly, but can be removed once we are on Python 3.9+ only - imports.add( - inspect.getmodule(param.annotation.__args__[0]).__name__ - ) - types.add(param.annotation._name) - else: - imports.add(mod) + imports.add(inspect.getmodule(param.annotation).__name__) + for t in typing.get_args(param.annotation): + imports.add(inspect.getmodule(t).__name__) except AttributeError: raise ValueError(f"Missing type annotation: {params}") imports.discard("builtins") diff --git a/docs/src/content/overview-installation.md b/docs/src/content/overview-installation.md index a65ae0fa4..8f7e86d5e 100644 --- a/docs/src/content/overview-installation.md +++ b/docs/src/content/overview-installation.md @@ -66,7 +66,7 @@ While there are plenty of options around[^1], we recommend the installation usin packages. Most of them (pip, virtualenv, pipenv, etc.) should just work, but we don't have the capacity to provide support for it. -1. Install a recent version of Python (we require at least 3.9). +1. Install a recent version of Python (we require at least 3.10). 2. Install [pipx](https://pipxproject.github.io/pipx/). 3. `pipx install mitmproxy` diff --git a/mitmproxy/master.py b/mitmproxy/master.py index a8e6bfc34..3484600a8 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -40,10 +40,7 @@ class Master: # may want to spawn tasks during the initial configuration phase, # which happens before run(). self.event_loop = event_loop or asyncio.get_running_loop() - try: - self.should_exit = asyncio.Event() - except RuntimeError: # python 3.9 and below - self.should_exit = asyncio.Event(loop=self.event_loop) # type: ignore + self.should_exit = asyncio.Event() mitmproxy_ctx.master = self mitmproxy_ctx.log = self.log # deprecated, do not use. mitmproxy_ctx.options = self.options diff --git a/mitmproxy/utils/signals.py b/mitmproxy/utils/signals.py index cad5e5d1f..4bdc7282f 100644 --- a/mitmproxy/utils/signals.py +++ b/mitmproxy/utils/signals.py @@ -17,13 +17,9 @@ from collections.abc import Callable from typing import Any from typing import cast from typing import Generic +from typing import ParamSpec from typing import TypeVar -try: - from typing import ParamSpec -except ImportError: # pragma: no cover - # Python 3.9 - from typing_extensions import ParamSpec # type: ignore P = ParamSpec("P") R = TypeVar("R") diff --git a/setup.py b/setup.py index 4578e7752..1c0f7c433 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,6 @@ setup( "Operating System :: POSIX", "Operating System :: Microsoft :: Windows", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", @@ -70,7 +69,7 @@ setup( "hook-dirs = mitmproxy.utils.pyinstaller:hook_dirs", ], }, - python_requires=">=3.9", + python_requires=">=3.10", # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#install-requires # It is not considered best practice to use install_requires to pin dependencies to specific versions. install_requires=[