From c0c37a0855c82bd7211d7c8d318731caaa879b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sun, 12 Sep 2021 10:54:35 +0200 Subject: [PATCH] DOC: add docs for expanded versioned_branches feature --- README.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1366c75d..45f54863 100644 --- a/README.md +++ b/README.md @@ -294,21 +294,58 @@ def f(): yield (a, b) ``` -### `if PY2` blocks +### Python2 and old Python3.x blocks Availability: - `--py3-plus` is passed on the commandline. ```python # input -if six.PY2: # also understands `six.PY3` and `not` and `sys.version_info` +import sys +if sys.version_info < (3,): # also understands `six.PY2` (and `not`), `six.PY3` (and `not`) print('py2') else: print('py3') # output +import sys print('py3') ``` +Availability: +- `--py36-plus` will remove Python <= 3.5 only blocks +- `--py37-plus` will remove Python <= 3.6 only blocks +- so on and so forth + +```python +# using --py36-plus for this example +# input +import sys +if sys.version_info < (3, 6): + print('py3.5') +else: + print('py3.6+') + +if sys.version_info <= (3, 5): + print('py3.5') +else: + print('py3.6+') + +if sys.version_info >= (3, 6): + print('py3.6+') +else: + print('py3.5') + +# output +import sys +print('py3.6+') + +print('py3.6+') + +print('py3.6+') +``` + +Note that `if` blocks without an `else` will not be rewriten as it could introduce a syntax error. + ### remove `six` compatibility code Availability: