[pytest-dev] decorators and signature-preserving wrappers

Sylvain MARIE sylvain.marie at se.com
Tue Mar 12 05:44:47 EDT 2019


(wrong title in previous email, sorry)



Dear pytest enthusiasts,



This is not pytest per se but quite low-level python so you may find it interesting also for pytest, that has many decorators.



--

Writing python decorators is quite a tideous process, in particular when you wish to add arguments, and in particular in two cases : all optional arguments, and one mandatory argument. Indeed in these two cases there is a need to disambiguate between no-parenthesis and with-parenthesis usage.



After having struggled with this pattern for two years in various open source and industrial projects, I ended up writing a library to hopefully solve this once and for all: https://smarie.github.io/python-decopatch/<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsmarie.github.io%2Fpython-decopatch%2F&data=02%7C01%7Csylvain.marie%40se.com%7Cec6cef6d1c6441e1c93208d6a6cf2ae1%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636879806075720620&sdata=jyaK3Sz%2BlDd64ZJQ3mwsNJY50TVXopHf2QkGlAA%2FopA%3D&reserved=0> . It is extensively tested (203 tests) against many combinations of signature/calls.

I would gladly appreciate any feedback !



Please note that there is a "PEP proposal draft" in the project page because I belive that the best a library can do will always be a poor workaround, where the interpreter or stdlib could really fix it properly.

Sorry for not providing too much implementation details in that page, my knowledge of the python interpreter is unfortunately quite limited.



--



Finally there is an additional topic around decorators : people tend to believe that decorators and function wrappers are the same, which is absolutely not the case. I used the famous `decorator` lib in many projects but I was not satisfied because it was solving both issues at the same time, maintaining the confusion. I therefore proposed https://smarie.github.io/python-makefun/<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsmarie.github.io%2Fpython-makefun%2F&data=02%7C01%7Csylvain.marie%40se.com%7Cec6cef6d1c6441e1c93208d6a6cf2ae1%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636879806075730607&sdata=CZPBXEbeL3s2bUQXjNpQQ%2FXvqTmwfHaRQgEJ9fjhrR8%3D&reserved=0> . In particular it provides an equivalent of `@functools.wraps` that is truly signature-preserving (based on the same recipe than `decorator`).

Once again, any feedback would be gladly appreciated !



Kind regards



--

Sylvain

De : pytest-dev <pytest-dev-bounces+sylvain.marie=se.com at python.org<mailto:pytest-dev-bounces+sylvain.marie=se.com at python.org>> De la part de Guilherme Zagatti
Envoyé : vendredi 8 mars 2019 17:42
À : pytest-dev at python.org<mailto:pytest-dev at python.org>
Objet : [pytest-dev] pytest-airflow plugin


[External email: Use caution with links and attachments]

________________________________


Dear Pytest Development Community,

My name is Guilherme Zagatti. I am a developer at Flowminder, an award winning social-enterprise especializing in the use of Big Data for international development.

We are big fans of pytest. We needed to integrate pytest with Airflow to develop data quality assurance tests before ingesting data to our databases. Therefore we created the pytest-airflow pluging.

We just made it available to pypi<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpypi.org%2Fproject%2Fpytest-airflow%2F&data=02%7C01%7Csylvain.marie%40se.com%7Cec6cef6d1c6441e1c93208d6a6cf2ae1%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636879806075730607&sdata=G4IFo2ndMgDYqF9K8EDADrEtSNjxsmeyJ21yJ9eojFw%3D&reserved=0> and open sourced in Github<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FFlowminder%2Fpytest-airflow&data=02%7C01%7Csylvain.marie%40se.com%7Cec6cef6d1c6441e1c93208d6a6cf2ae1%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636879806075740616&sdata=ThQ67TmQxVSdu6saRxaeO4l4rSGxXDHmaDFJ45iPRXA%3D&reserved=0>. It would be great to receive feedback from the pytest community and your suggestions on how to best promote the plugin to other users.

I am available to provide further details on the plugin. In the meanwhile, I have made available an architecture documentation<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FFlowminder%2Fpytest-airflow%2Fblob%2Fmaster%2Fdocs%2Farchitecture.md&data=02%7C01%7Csylvain.marie%40se.com%7Cec6cef6d1c6441e1c93208d6a6cf2ae1%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636879806075750626&sdata=UH2HFXbIj784SCAptwqotmj5o7mSRTUIlgnFSOC71p8%3D&reserved=0> that contains a primer on pytest and detailed explanation of the plugin. Perhaps the contents of this document is of interest to the pytest community more generally. Feel free to provide comments and share more widely.

Again, very-well done for maintaining pytest.

Best,

Guilherme Zagatti

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20190312/eaaff454/attachment-0001.html>


More information about the pytest-dev mailing list