Repository: py-pdf/pypdf
Pull request: MAINT: Relax typing_extensions version
This relaxes the version of `typing_extensions` required by PyPDF as proposed in #1950.

Please note that this change is not reflected in CI due to the reasons outlined in https://github.com/py-pdf/pypdf/issues/1950#issuecomment-1627387294, but I have tested it locally and some time ago on my fork of the project.

Closes #1950.

Problem statement:
Loosen dependency on typing-extensions
## Explanation

`pypdf` currently depends on `typing_extensions>=3.10`. Is there any reason for this minimum version?

Background: I am currently bound to using 3.7.4.3 to maintain compatibility with some other packages. Running the tests locally with `typing_extensions==3.7.4.3` does not seem to introduce any issues on Python 3.6.15 and Python 3.9.16.

Hints from issue discussion:
TypeAlias was the reason: https://github.com/py-pdf/pypdf/commit/84460f54aa4721db36452fe510f8063838e358d5 see https://github.com/py-pdf/pypdf/pull/1277
This appears to be wrong, as *TypeAlias* is being defined in https://github.com/python/typing_extensions/blob/3.7.4.3/typing_extensions/src_py3/typing_extensions.py#L2076-L2168 on the 3.7.4.3 tag. Additionally, running the tests with 3.7.4.3 on Python 3.6 works completely fine in my case, as mentioned above.
https://github.com/python/typing_extensions/commit/d362ccb6504bf52618796822e8e6ffa9091575a4 looks like it was added in [3.10.0.0](https://github.com/python/typing_extensions/releases/tag/3.10.0.0)

https://github.com/python/typing_extensions/commit/6d287f054b4f535a8b0ff1c249a28795894690d0 looks as if it was added in `3.7.4.2`.

In any case our CI should capture issues. Feel free to open a PR that downgrades the minimum requirement of typing_extensions. If the CI runs through, I'm happy with it :-)
I will see if I manage to get this to work without modifying too much on the CI side. For now, the CI requirements block this due to the fixed *mypy* and *importlib-metadata* versions.
> In any case our CI should capture issues.

This only holds true if `requirements/ci.txt` is updated as well to reflect the new version.

Checking this, it seems to like updating `requirements/ci.in` and `requirements/ci.txt` accordingly for CI seems to work for *pytest* (as already observed in my local tests).

But: Apparently *mypy* made the same (wrong) assumptions in https://github.com/python/mypy/commit/71c5a0e37741a4452803122ef23b76c022fab607 and requires pinning to a maximum of `mypy==0.910` if we want to relax the *typing_extensions* version as proposed. This reports some "new" *mypy* issues:

```none
pypdf/generic/_data_structures.py:869: error: Incompatible types in assignment (expression has type "None", variable has type "ArrayObject")  [assignment]
pypdf/filters.py:785: error: Argument "formats" to "open" has incompatible type "Tuple[str]"; expected "Union[List[str], Tuple[str, Any], None]"  [arg-type]
pypdf/filters.py:867: error: Argument "formats" to "open" has incompatible type "Tuple[str]"; expected "Union[List[str], Tuple[str, Any], None]"  [arg-type]
pypdf/_writer.py:[12](https://github.com/stefan6419846/pypdf/actions/runs/5495158775/jobs/10014434259#step:12:13)83: error: Argument 1 to "FileIO" has incompatible type "Union[Path, str]"; expected "Union[str, bytes, int]"  [arg-type]
pypdf/_writer.py:2686: error: Argument 1 to "FileIO" has incompatible type "Union[Path, str]"; expected "Union[str, bytes, int]"  [arg-type]
pypdf/_merger.py:254: error: Argument 1 to "FileIO" has incompatible type "Union[Path, str]"; expected "Union[str, bytes, int]"  [arg-type]
Found 6 errors in 4 files (checked 33 source files)
```

Given this, I am not sure whether it is desired on the PyPDF side to officially support this older *typing_extensions* version, as this basically requires us to rewrite/change the GitHub workflows to ensure compatibility accordingly:

* One complete run for each supported Python version with `typing_extensions==3.7.4.2`, but with *mypy* checks disabled.
* One complete run for each supported Python version with `typing_extensions==3.10` with the *mypy* checks enabled.

Commit message: MAINT: relax typing_extensions version

Patch to review:
diff --git a/pyproject.toml b/pyproject.toml
index efbf681b0..e75f78c22 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -28,7 +28,7 @@ classifiers = [
     "Typing :: Typed",
 ]
 dependencies = [
-    "typing_extensions >= 3.10.0.0; python_version < '3.10'",
+    "typing_extensions >= 3.7.4.2; python_version < '3.10'",
     "dataclasses; python_version < '3.7'",
 ]
 


Code review comments:
diff_hunk: @@ -28,7 +28,7 @@ classifiers = [
     "Typing :: Typed",
 ]
 dependencies = [
-    "typing_extensions >= 3.10.0.0; python_version < '3.10'",
+    "typing_extensions >= 3.7.4.2; python_version < '3.10'",
path: pyproject.toml
text: @user1:
```suggestion
    "typing_extensions >= 3.7.4.3; python_version < '3.10'",
```