diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2021-03-31 05:38:08 +0200 |
---|---|---|
committer | Michele Simionato <michele.simionato@gmail.com> | 2021-03-31 05:38:08 +0200 |
commit | f77bcbce45deb6757ef17d06033ef00a8b85c6df (patch) | |
tree | 4378f9c09925e5e3c640f45bb4fac48f1e6efbc0 | |
parent | 20a43882ca3d3771b8f76ec37c974592d7e299aa (diff) | |
parent | 5b078615f9ccd2b4bf25ae808ea3820dca06adf2 (diff) | |
download | python-decorator-git-f77bcbce45deb6757ef17d06033ef00a8b85c6df.tar.gz |
Merge branch 'master' of github.com:micheles/decorator into 4.5
-rw-r--r-- | .github/workflows/python-package.yml | 39 | ||||
-rw-r--r-- | CHANGES.md | 2 | ||||
-rw-r--r-- | docs/documentation.md | 31 | ||||
-rw-r--r-- | src/tests/documentation.py | 27 |
4 files changed, 67 insertions, 32 deletions
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..6135835 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: decorator + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['2.7', '3.5', '3.6', '3.7', '3.8', '3.9'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 + python -m pip install -e . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + python src/tests/test.py -v @@ -3,6 +3,8 @@ HISTORY ## unreleased +Ported CI from Travis to GitHub + ## 4.4.2 (2020-02-29) Sylvan Mosberger (https://github.com/Infinisil) contributed a patch to diff --git a/docs/documentation.md b/docs/documentation.md index 898a46d..fb41ae9 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -37,7 +37,7 @@ What's New in version 4 - **New documentation** There is now a single manual for all Python versions, so I took the - opportunity to overhaul the documentation and to move it to readthedocs.org. + opportunity to overhaul the documentation. Even if you are a long-time user, you may want to revisit the docs, since several examples have been improved. @@ -93,7 +93,7 @@ some experience and it is not as easy as it could be. For instance, typical implementations of decorators involve nested functions, and we all know that flat is better than nested. -The aim of the ``decorator`` module is to simplify the usage of +The aim of the ``decorator`` module it to simplify the usage of decorators for the average programmer, and to popularize decorators by showing various non-trivial examples. Of course, as all techniques, decorators can be abused (I have seen that) and you should not try to @@ -478,6 +478,9 @@ calling func with args (), {} ``` +Decorator factories +------------------------------------------- + The `decorator` function can also be used to define factories of decorators, i.e. functions returning decorators. In general you can just write something like this: @@ -490,9 +493,8 @@ def decfactory(param1, param2, ...): ``` This is fully general but requires an additional level of nesting. For this -reason since version 4.2 there is a facility to build -decorator factories by using a single caller with default arguments i.e. -writing something like this: +reason since version 4.2 there is a facility to build decorator factories by +using a single caller with default arguments i.e. writing something like this: ```python def caller(f, param1=default1, param2=default2, ..., *args, **kw): @@ -506,22 +508,17 @@ restriction, there exists an unique default decorator, i.e. the member of the family which uses the default values for all parameters. Such decorator can be written as ``decfactory()`` with no parameters specified; moreover, as a shortcut, it is also possible to elide the parenthesis, -a feature much requested by the users. For years I have been opposite -to this feature request, since having explicit parenthesis to me is more clear +a feature much requested by the users. For years I have been opposing +the request, since having explicit parenthesis to me is more clear and less magic; however once this feature entered in decorators of the Python standard library (I am referring to the [dataclass decorator]( https://www.python.org/dev/peps/pep-0557/)) I finally gave up. -The example below will show how it works in practice. - -Decorator factories -------------------------------------------- - -Sometimes one has to deal with blocking resources, such as ``stdin``. -Sometimes it is better to receive a "busy" message than just blocking -everything. -This can be accomplished with a suitable family of decorators (decorator -factory), parameterize by a string, the busy message: +The example below shows how it works in practice. The goal is to +convert a function relying on a blocking resource into a function +returning a "busy" message if the resource is not available. +This can be accomplished with a suitable family of decorators +parameterize by a string, the busy message: ```python diff --git a/src/tests/documentation.py b/src/tests/documentation.py index c9f6265..28369ed 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -382,6 +382,9 @@ calling func with args (), {} ``` +Decorator factories +------------------------------------------- + The `decorator` function can also be used to define factories of decorators, i.e. functions returning decorators. In general you can just write something like this: @@ -394,9 +397,8 @@ def decfactory(param1, param2, ...): ``` This is fully general but requires an additional level of nesting. For this -reason since version 4.2 there is a facility to build -decorator factories by using a single caller with default arguments i.e. -writing something like this: +reason since version 4.2 there is a facility to build decorator factories by +using a single caller with default arguments i.e. writing something like this: ```python def caller(f, param1=default1, param2=default2, ..., *args, **kw): @@ -410,22 +412,17 @@ restriction, there exists an unique default decorator, i.e. the member of the family which uses the default values for all parameters. Such decorator can be written as ``decfactory()`` with no parameters specified; moreover, as a shortcut, it is also possible to elide the parenthesis, -a feature much requested by the users. For years I have been opposite -to this feature request, since having explicit parenthesis to me is more clear +a feature much requested by the users. For years I have been opposing +the request, since having explicit parenthesis to me is more clear and less magic; however once this feature entered in decorators of the Python standard library (I am referring to the [dataclass decorator]( https://www.python.org/dev/peps/pep-0557/)) I finally gave up. -The example below will show how it works in practice. - -Decorator factories -------------------------------------------- - -Sometimes one has to deal with blocking resources, such as ``stdin``. -Sometimes it is better to receive a "busy" message than just blocking -everything. -This can be accomplished with a suitable family of decorators (decorator -factory), parameterize by a string, the busy message: +The example below shows how it works in practice. The goal is to +convert a function relying on a blocking resource into a function +returning a "busy" message if the resource is not available. +This can be accomplished with a suitable family of decorators +parameterize by a string, the busy message: $$blocking |