Sub topic 17
After release: yanking, deprecation, and changelogs
This chapter assumes you have already published greeter to PyPI as described in the earlier chapters. You should know how to build with python -m build, how versions follow PEP 440, and how to log in to the PyPI web interface. Publishing is not the last step. A release stays on the index permanently, so you need a plan for what to do when it is wrong, when an API has to go away, and how to tell users what changed.
Releases are permanent
PyPI does not let you replace a file once it is uploaded. If you delete greeter-0.1.0-py3-none-any.whl and upload a corrected build, PyPI rejects it because that filename can never be reused. Deleting a release can also break anyone who pinned it, and it frees nothing for you to reuse.
So the working rule is simple: never try to fix a release in place. Publish a new version, and mark the bad one so installers avoid it.
Yanking a bad release
Yanking is defined in PEP 592. A yanked release stays on PyPI and its files stay downloadable, but installers skip it unless nothing else can satisfy the request.
The exact behavior of pip is:
pip install greeterignores the yanked version and picks the newest non-yanked one.pip install "greeter>=0.1"also ignores it.pip install "greeter==0.1.0"still installs it, because an exact pin is treated as an explicit request. pip prints a warning that includes your yank reason.
That last rule keeps existing lockfiles and reproducible builds working, while new installs move away from the broken release.
You yank from the PyPI web interface. Open your project, go to Manage, choose the release, and use the yank option. Enter a reason. The reason is shown to users in the warning, so make it useful. Twine has no yank command. You can reverse a yank from the same page, which makes it much safer than deleting.
When to yank and when not to
| Situation | Action |
|---|---|
| Wheel is missing files and `import greeter` fails | Yank, then release a fixed version |
| Security vulnerability in released code | Yank, release a fix, publish an advisory |
| Typo in the README on PyPI | Release a new version, or a post-release |
| Old API you want to remove eventually | Deprecate, do not yank |
| Project abandoned | Say so in the README; do not yank everything |
For a metadata-only mistake such as a wrong classifier, PEP 440 allows a post-release like 0.1.0.post1. It signals "same code, corrected packaging". A normal patch release such as 0.1.1 is usually clearer and works with every tool, so use it by default.
The fix-forward workflow
The diagram shows the sequence after you discover a bad release.
Yank first when users are being hurt right now, because it takes effect immediately. The fix can follow at its own pace. Then run the same checks as for any release. A rushed second release that is also broken is a common way to make an incident worse.
Deprecating features
Yanking handles bad releases. Removing an API from a good release needs a different tool: a deprecation period. Users get at least one release in which the old name still works and tells them what to use instead.
Python's warnings module is the standard mechanism. Suppose greeter renames greet_user to greet:
# src/greeter/__init__.py
import warnings
from importlib.metadata import version
__version__ = version("greeter")
def greet(name: str) -> str:
return f"Hello, {name}!"
def greet_user(name: str) -> str:
warnings.warn(
"greet_user() is deprecated and will be removed in greeter 2.0; "
"use greet() instead.",
DeprecationWarning,
stacklevel=2,
)
return greet(name)Three details matter:
stacklevel=2points the warning at the caller's line, not at the line inside your library. Without it, users see a location they cannot change.- The message names the replacement and the removal version. "Deprecated" alone gives users nothing to act on.
- The category is
DeprecationWarning. Python hides this category by default, except for code running in__main__and under test runners such as pytest. That is intended: it reaches developers, not end users of an application. If the warning targets end users of your tool, useFutureWarning, which is always shown.
On Python 3.13 and later, warnings.deprecated (PEP 702) can decorate the function, and type checkers understand it. The typing_extensions package provides the same decorator for older versions. Since greeter declares requires-python = ">=3.9" and no dependencies, the plain warnings.warn call keeps it dependency-free.
Test the deprecation so you notice if it is accidentally removed:
# tests/test_deprecation.py
import pytest
from greeter import greet_user
def test_greet_user_warns_and_still_works():
with pytest.warns(DeprecationWarning, match="use greet"):
assert greet_user("Ada") == "Hello, Ada!"Pairing deprecation with versioning
Under semantic versioning, adding a deprecation warning is a minor change (0.2.0, or 1.3.0 for a stable library) because nothing breaks. Removing the function is a breaking change and belongs in the next major version. Before 1.0, many projects remove deprecated names in a minor release. If you do, say so clearly in the changelog.
A reasonable policy is to keep a deprecated name for at least two minor releases or six months, whichever is longer. Write the policy in your README so users can plan.
Writing a changelog
A changelog is a human-written list of what changed between versions. A git log is not a substitute, because it describes commits, not effects on users. The widely used Keep a Changelog format groups entries under headings such as Added, Changed, Deprecated, Removed, Fixed, and Security, newest version first.
# Changelog
## [Unreleased]
## [0.2.0] - 2026-12-10
### Added
- `greet()` accepts an optional `punctuation` argument.
### Deprecated
- `greet_user()`. Use `greet()` instead. It will be removed in 2.0.
## [0.1.1] - 2026-11-26
### Fixed
- Wheel now includes `py.typed`; type checkers can read the annotations.
## [0.1.0] - 2026-11-20 [YANKED]
### Fixed in 0.1.1
- Release was missing `py.typed`.Keep an [Unreleased] section at the top and add entries as you merge changes. At release time, rename it to the new version and date. Mark yanked versions in the changelog so a reader who finds an old pin understands why it warns.
Make the changelog easy to find by adding it to the project URLs. PyPI shows these links in the sidebar:
[project.urls]
Homepage = "https://github.com/example/greeter"
Changelog = "https://github.com/example/greeter/blob/main/CHANGELOG.md"
Issues = "https://github.com/example/greeter/issues"Add this table to pyproject.toml, and release a new version for PyPI to show it. Metadata on an existing release cannot be edited.
Common mistakes
- Deleting instead of yanking. Deletion breaks pinned installs and does not let you reuse the filename.
- Yanking without a reason. Users see only a bare warning and cannot judge how serious it is.
- Removing an API with no warning period. This forces a major version bump and surprises users.
- Missing
stacklevel. The warning points inside your library, and users cannot find their own call. - Changelog written from
git log. It lists commit titles and hides what matters to users.
Exercise
You released greeter 0.3.0, and users report that import greeter fails on Python 3.9 because of a syntax feature you used. Which steps do you take, and what happens to a user whose requirements file says greeter==0.3.0?
Show answer
Yank 0.3.0 on PyPI with a reason such as "fails to import on Python 3.9", fix the code (or raise requires-python if you drop 3.9), bump to 0.3.1, build, run twine check, test the install in a clean virtual environment, publish, and add a changelog entry that marks 0.3.0 as yanked. Do not delete 0.3.0. A user with greeter==0.3.0 still gets that exact version, because an exact pin overrides a yank, but pip prints a warning with your reason. Users who install greeter or greeter>=0.3 get 0.3.1.
Exercise
You want to retire greet_user(). Write the line that issues the warning so it points at the user's code, say which category you would choose for a library that other developers import, and say which kind of version bump adds the warning.
Show answer
Use warnings.warn("greet_user() is deprecated; use greet() instead.", DeprecationWarning, stacklevel=2). stacklevel=2 makes the warning report the caller's line. DeprecationWarning suits a library imported by developers, because pytest and __main__ code show it. Adding the warning is a minor version bump (for example 0.2.0). Removing the function later is a breaking change that belongs in a major version.