sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.44k stars 479 forks source link

Meta-ticket: Review of Python 3 features that sagelib should use systematically #29756

Open mkoeppe opened 4 years ago

mkoeppe commented 4 years ago

For Sage 10.4, all of the following features can be used

Python 3.6 features (https://docs.python.org/3.10/whatsnew/3.6.html):

Python 3.7 features (https://docs.python.org/3.10/whatsnew/3.7.html)

Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html)

Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html)

Features introduced in Python 3.10 or later cannot be used in Sage yet because we support system Python 3.9.x

Python 3.10 features (https://docs.python.org/3.10/whatsnew/3.10.html):

Python 3.11 features (https://docs.python.org/3.11/whatsnew/3.11.html):

Python 3.12 features (https://docs.python.org/3.12/whatsnew/3.12.html):

Python 3.13 features (https://docs.python.org/3.13/whatsnew/3.13.html):

See also


CC: @fchapoton @dimpase @jhpalmieri @tobiasdiez @tscrim @nthiery @slel @nbruin

Component: python3

Keywords: sd109

Issue created by migration from https://trac.sagemath.org/ticket/29756

mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,5 +1,5 @@

-- types
+- types (#29775)
 - native namespace packages - #28925
 - ...?
egourgoulhon commented 4 years ago
comment:2

About types, has a general policy been discussed on sage-devel?

dimpase commented 4 years ago
comment:3

typing is a standard Python 3 module, and it allows one to catch more errors.. Why would one have anything against it?

kcrisman commented 4 years ago
comment:4

typing is a standard Python 3 module, and it allows one to catch more errors.. Why would one have anything against it?

Are there reasons (e.g. performance) not to use it in certain circumstances?

mkoeppe commented 4 years ago
comment:5

I created this ticket as a place for discussions of these new features to make sure that we use them systematically in the Sage library, rather than in an ad-hoc way.

For example, for typing, I think there are opportunities to integrate it with the various dynamically generated classes that come in from the category system, as I noted in #29775.

tobiasdiez commented 4 years ago
comment:6

There shouldn't be any performance issues with typing as it is deactivated on runtime (the only additional overhead is the import of the typing package). See also the discussion here https://realpython.com/python-type-checking/#pros-and-cons

mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,5 +1,6 @@

 - types (#29775)
 - native namespace packages - #28925
+- `yield from` - #29857
 - ...?
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -2,5 +2,6 @@
 - types (#29775)
 - native namespace packages - #28925
 - `yield from` - #29857
+- [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
 - ...?
slel commented 4 years ago

Description changed:

--- 
+++ 
@@ -3,5 +3,6 @@
 - native namespace packages - #28925
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
-- ...?
+- f-strings (formatted strings)
+  - ...?
slel commented 4 years ago

Description changed:

--- 
+++ 
@@ -4,5 +4,8 @@
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
 - f-strings (formatted strings)
-  - ...?
+- ...?

+See also:
+
+- #29728: Meta-ticket: improve compatibility with the Python library
slel commented 4 years ago
comment:11

Regarding f-strings, see this comment:

mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -4,6 +4,7 @@
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
 - f-strings (formatted strings)
+- keyword-only parameters (#16607)
 - ...?

 See also:
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -5,6 +5,7 @@
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
 - f-strings (formatted strings)
 - keyword-only parameters (#16607)
+- new import machinery - #27074    (Make `.sage` modules importable)
 - ...?

 See also:
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -6,6 +6,7 @@
 - f-strings (formatted strings)
 - keyword-only parameters (#16607)
 - new import machinery - #27074    (Make `.sage` modules importable)
+- `__matmul__` (infix `@` operator) - #22760
 - ...?

 See also:
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -7,6 +7,7 @@
 - keyword-only parameters (#16607)
 - new import machinery - #27074    (Make `.sage` modules importable)
 - `__matmul__` (infix `@` operator) - #22760
+- `from ..a import b`
 - ...?

 See also:
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,5 +1,5 @@

-- types (#29775)
+- types (#29775, #30381)
 - native namespace packages - #28925
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -13,3 +13,5 @@
 See also:

 - #29728: Meta-ticket: improve compatibility with the Python library
+- #30384: Adopt the “time window-based” policy for support of Python versions from NEP 29
+
mwageringel commented 4 years ago
comment:18

Replying to @egourgoulhon:

About types, has a general policy been discussed on sage-devel?

+1 for using typing. Return types in particular are useful for tab-completion on the result of function calls. For example

sage: "hello".upper().lower().upper()

this tab-completes without evaluating the code (i.e. without setting IPython's IPCompleter.greedy config option).

mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,5 +1,7 @@

-- types (#29775, #30381)
+- static typing (#29775, #30381)
+  - #30381 Python 3 typing/protocols/ABCs
+  - #30511 Type hints (`__annotations__`) and coercion/categories/Cython
 - native namespace packages - #28925
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,7 +1,8 @@

-- static typing (#29775, #30381)
+- static typing
+  - #29775 Add a bit of typing to manifold code
   - #30381 Python 3 typing/protocols/ABCs
-  - #30511 Type hints (`__annotations__`) and coercion/categories/Cython
+  - #30511 Type hints (`__annotations__`) and coercion/Cython
 - native namespace packages - #28925
 - `yield from` - #29857
 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
mkoeppe commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,4 @@
+Python 3.6 features

 - static typing
   - #29775 Add a bit of typing to manifold code
@@ -5,7 +6,6 @@
   - #30511 Type hints (`__annotations__`) and coercion/Cython
 - native namespace packages - #28925
 - `yield from` - #29857
-- [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
 - f-strings (formatted strings)
 - keyword-only parameters (#16607)
 - new import machinery - #27074    (Make `.sage` modules importable)
@@ -13,8 +13,14 @@
 - `from ..a import b`
 - ...?

+Python 3.7+ features
+
+- [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
+
+
 See also:

 - #29728: Meta-ticket: improve compatibility with the Python library
 - #30384: Adopt the “time window-based” policy for support of Python versions from NEP 29
+- #30551 Drop Python 3.6 support
mwageringel commented 4 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,9 @@

 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)

+Python 3.8+ features:
+
+- positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))

 See also:
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,8 @@

 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)

+- `from `__future__` import annotations` (#31006)
+
 Python 3.8+ features:

 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -15,7 +15,7 @@

 Python 3.7+ features

-- [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (requires python 3.7 or backport `importlib_resources` if we want to support 3.6 - but that does not support resources within namespace packages)
+- [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (#31306)

 - `from `__future__` import annotations` (#31006)
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,5 +1,6 @@
 Python 3.6 features

+- [https://docs.python.org/3/library/pathlib.html pathlib](https://docs.python.org/3/library/pathlib.html pathlib)
 - static typing
   - #29775 Add a bit of typing to manifold code
   - #30381 Python 3 typing/protocols/ABCs
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,6 +1,6 @@
 Python 3.6 features

-- [https://docs.python.org/3/library/pathlib.html pathlib](https://docs.python.org/3/library/pathlib.html pathlib)
+- [pathlib](https://docs.python.org/3/library/pathlib.html)
 - static typing
   - #29775 Add a bit of typing to manifold code
   - #30381 Python 3 typing/protocols/ABCs
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -8,7 +8,7 @@
 - native namespace packages - #28925
 - `yield from` - #29857
 - f-strings (formatted strings)
-- keyword-only parameters (#16607)
+- keyword-only parameters (#16607, #31309)
 - new import machinery - #27074    (Make `.sage` modules importable)
 - `__matmul__` (infix `@` operator) - #22760
 - `from ..a import b`
mkoeppe commented 3 years ago
comment:29

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.

mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,4 +1,4 @@
-Python 3.6 features
+Python 3.6 features (https://docs.python.org/3.10/whatsnew/3.6.html):

 - [pathlib](https://docs.python.org/3/library/pathlib.html)
 - static typing
@@ -14,15 +14,19 @@
 - `from ..a import b`
 - ...?

-Python 3.7+ features
+Python 3.7 features (https://docs.python.org/3.10/whatsnew/3.7.html):

 - [importlib.resources](https://docs.python.org/3/library/importlib.html#module-importlib.resources) (#31306)

 - `from `__future__` import annotations` (#31006)

-Python 3.8+ features:
+Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html):

 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
+
+Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):
+
+Python 3.10 features (https://docs.python.org/3.10/whatsnew/3.10.html):

 See also:
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -20,6 +20,8 @@

 - `from `__future__` import annotations` (#31006)

+- https://docs.python.org/3/library/dataclasses.html
+
 Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html):

 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,6 @@
+**For Sage 9.4, all of the following features can be used:**
+
+
 Python 3.6 features (https://docs.python.org/3.10/whatsnew/3.6.html):

 - [pathlib](https://docs.python.org/3/library/pathlib.html)
@@ -22,9 +25,14 @@

 - https://docs.python.org/3/library/dataclasses.html

+
+**Using features introduced in Python 3.8 or later cannot be used in Sage yet because we support system Python 3.7.x.**
+
 Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html):

 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
+- `f'{expr=}'` https://docs.python.org/3.10/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging
+- PEP 590: Vectorcall: a fast calling protocol for CPython https://docs.python.org/3.10/whatsnew/3.8.html#pep-590-vectorcall-a-fast-calling-protocol-for-cpython

 Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -33,6 +33,10 @@
 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
 - `f'{expr=}'` https://docs.python.org/3.10/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging
 - PEP 590: Vectorcall: a fast calling protocol for CPython https://docs.python.org/3.10/whatsnew/3.8.html#pep-590-vectorcall-a-fast-calling-protocol-for-cpython
+- `functools.cached_property()` https://docs.python.org/3.10/whatsnew/3.8.html#functools
+- `pprint(sort_dicts=False)`
+- `shutil.copytree(dirs_exist_ok=True)`
+

 Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):
mkoeppe commented 3 years ago

Description changed:

--- 
+++ 
@@ -5,6 +5,8 @@

 - [pathlib](https://docs.python.org/3/library/pathlib.html)
 - static typing
+  - #32058 add typing annotations in permutations
+  - #32067 Developer manual: Section on typing annotations
   - #29775 Add a bit of typing to manifold code
   - #30381 Python 3 typing/protocols/ABCs
   - #30511 Type hints (`__annotations__`) and coercion/Cython
mkoeppe commented 2 years ago

Description changed:

--- 
+++ 
@@ -28,16 +28,21 @@
 - https://docs.python.org/3/library/dataclasses.html

-**Using features introduced in Python 3.8 or later cannot be used in Sage yet because we support system Python 3.7.x.**
+Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html) can be used as soon as #32937 is merged:

-Python 3.8 features (https://docs.python.org/3.10/whatsnew/3.8.html):
-
+- assignment expressions `:=` (https://docs.python.org/3.10/whatsnew/3.8.html#assignment-expressions)
 - positional-only parameters ([PEP 570](https://www.python.org/dev/peps/pep-0570/))
 - `f'{expr=}'` https://docs.python.org/3.10/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging
 - PEP 590: Vectorcall: a fast calling protocol for CPython https://docs.python.org/3.10/whatsnew/3.8.html#pep-590-vectorcall-a-fast-calling-protocol-for-cpython
 - `functools.cached_property()` https://docs.python.org/3.10/whatsnew/3.8.html#functools
 - `pprint(sort_dicts=False)`
-- `shutil.copytree(dirs_exist_ok=True)`
+- `shutil.copytree(dirs_exist_ok=True)` https://docs.python.org/3.10/whatsnew/3.8.html#shutil
+- `as_integer_ratio`, `__index__` special method (https://docs.python.org/3.10/whatsnew/3.8.html#other-language-changes)
+- `math.dist`, `hypot`, `prod`, `perm`, `comb`, `isqrt` https://docs.python.org/3.10/whatsnew/3.8.html#math
+- `typing.TypedDict`, `typing.Literal`, `Final`, `Protocol` https://docs.python.org/3.10/whatsnew/3.8.html#typing
+
+
+**Using features introduced in Python 3.9 or later cannot be used in Sage yet because we support system Python 3.8.x.**

 Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):
mkoeppe commented 2 years ago

Description changed:

--- 
+++ 
@@ -49,6 +49,9 @@

 Python 3.10 features (https://docs.python.org/3.10/whatsnew/3.10.html):

+Python 3.11 features (https://docs.python.org/3.11/whatsnew/3.11.html):
+
+
 See also:

 - #29728: Meta-ticket: improve compatibility with the Python library
mkoeppe commented 2 years ago

Description changed:

--- 
+++ 
@@ -42,7 +42,7 @@
 - `typing.TypedDict`, `typing.Literal`, `Final`, `Protocol` https://docs.python.org/3.10/whatsnew/3.8.html#typing

-**Using features introduced in Python 3.9 or later cannot be used in Sage yet because we support system Python 3.8.x.**
+**Features introduced in Python 3.9 or later cannot be used in Sage yet because we support system Python 3.8.x.**

 Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):
mkoeppe commented 2 years ago

Description changed:

--- 
+++ 
@@ -1,4 +1,4 @@
-**For Sage 9.4, all of the following features can be used:**
+**For Sage 9.7, all of the following features can be used:**

 Python 3.6 features (https://docs.python.org/3.10/whatsnew/3.6.html):
mkoeppe commented 2 years ago

Description changed:

--- 
+++ 
@@ -48,6 +48,8 @@
 Python 3.9 features (https://docs.python.org/3.10/whatsnew/3.9.html):

 Python 3.10 features (https://docs.python.org/3.10/whatsnew/3.10.html):
+- #34678: `match ... case`
+

 Python 3.11 features (https://docs.python.org/3.11/whatsnew/3.11.html):