


Our code is so interdependent! Adding dependencies to projects is just how code is done.
Every time somebody sneezes a new dependency is added to a project somewhere.
It is kinda great that we are on this side of the copy-right debate, where the default is building things on top of other people's work, and not shooting at everybody, who dares to even look in the direction of my code. But... who is going to upgrade all these dependencies all the time?
In the perfect world, we are a community and we all keep the libs upgraded to the latest versions, right?
Wrong! Devs need to be softly pushed to do the right thing. Yes, softly, so they don't notice they are being pushed ????.
Step 1: First we need to listen to deprecation warnings
We are using pytest, so this step is easy-peasy for us.
Starting from version 3.1, pytest now automatically catches warnings during test execution and displays them at the end of the session:
- Pytest: How to capture warnings
like this:
============================= warnings summary ============================= test_bla_bla_bla.py::test_test .../some_file.py:65: PydanticDeprecatedSince20: `pydantic.config.Extra` is deprecated, use literal values instead (e.g. `extra='allow'`). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/ extra=Extra.allow, .../marshmallow/fields.py:1186: RemovedInMarshammlow4Warning: The 'default' argument to fields is deprecated. Use 'dump_default' instead. super().__init__(**kwargs) ======================= 1 passed, 2 warnings in 0.12s =======================
Step 2: Pick the warnings you want to get rid of
I saw the marshmallow warning, looked at the code and saw that it was a simple fix.
So, I'm choosing RemovedInMarshammlow4Warning.
Step 3: Make deprecation warnings fail the tests
Again, we are using pytest, so this step is also easy-peasy for us.
Just add this to the config file:
[tool.pytest.ini_options] ... filterwarnings = [ "error::marshmallow.warnings.RemovedInMarshmallow4Warning" ]
- Pytest: Controlling warnings
Now every test that triggers this deprecation warning will fail.
Step 4: Fix the code
Unfortunately, you have to take one for the team here. You have to go and fix all the places where this warning is triggered.
I know.. it's unfair.
It's a lot of work, it's tedious work and you won't even be able to brag to your boss about it, because it is too technical and generally perceived as irrelevant from their standpoint.
And everything this does is help the next person (who won't be you), who will upgrade marshmallow and nothing in code will break. So, they won't thank you either, because they won't even notice anything has been done.
So, ... what I'm saying is: sometimes you need to do the right thing, and nobody will thank you for it.
But I will know. And you will know. ?
Step 5: Lean back and listen to Slack convos and GitHub comments
Eventually, there should be one message somewhere of somebody being confused: they wrote the code the same as last time, but this time, the tests fail, what's going on?
And you can say: "oh, hard to say, but I do see this is a deprecated feature, that must be the reason". ?
External links
- Pytest: How to capture warnings
- Python: The warnings filter
The above is the detailed content of How to encourage developers to fix Python warnings for deprecated features. For more information, please follow other related articles on the PHP Chinese website!

The basic syntax for Python list slicing is list[start:stop:step]. 1.start is the first element index included, 2.stop is the first element index excluded, and 3.step determines the step size between elements. Slices are not only used to extract data, but also to modify and invert lists.

Listsoutperformarraysin:1)dynamicsizingandfrequentinsertions/deletions,2)storingheterogeneousdata,and3)memoryefficiencyforsparsedata,butmayhaveslightperformancecostsincertainoperations.

ToconvertaPythonarraytoalist,usethelist()constructororageneratorexpression.1)Importthearraymoduleandcreateanarray.2)Uselist(arr)or[xforxinarr]toconvertittoalist,consideringperformanceandmemoryefficiencyforlargedatasets.

ChoosearraysoverlistsinPythonforbetterperformanceandmemoryefficiencyinspecificscenarios.1)Largenumericaldatasets:Arraysreducememoryusage.2)Performance-criticaloperations:Arraysofferspeedboostsfortaskslikeappendingorsearching.3)Typesafety:Arraysenforc

In Python, you can use for loops, enumerate and list comprehensions to traverse lists; in Java, you can use traditional for loops and enhanced for loops to traverse arrays. 1. Python list traversal methods include: for loop, enumerate and list comprehension. 2. Java array traversal methods include: traditional for loop and enhanced for loop.

The article discusses Python's new "match" statement introduced in version 3.10, which serves as an equivalent to switch statements in other languages. It enhances code readability and offers performance benefits over traditional if-elif-el

Exception Groups in Python 3.11 allow handling multiple exceptions simultaneously, improving error management in concurrent scenarios and complex operations.

Function annotations in Python add metadata to functions for type checking, documentation, and IDE support. They enhance code readability, maintenance, and are crucial in API development, data science, and library creation.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
