Skip to content
Myr

Updated docs for upgrade information.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 0df815a · Browse files · 2 files+42 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+42 added−0 removed

  • other:+42 added−0 removed

2 files+42 added−0 removed

modified:docs/index.rst+1 added
89 unmodified lines
90.. toctree::91 :maxdepth: 29293 changelog94 upgrading95 license
added:docs/upgrading.rst+41 added
1Upgrading To Newer Releases2===========================34Click attempts the highest level of backwards compatibility but sometimes5this is not entirely possible. In case we need to break backwards6compatibility this document gives you information about how to upgrade or7handle backwards compatibility properly.89Upgrading to 2.010----------------1112Click 2.0 has one breaking change which is the signature for parameter13callbacks. Before 2.0 the callback was invoked with ``(ctx, value)``14wheras now it's ``(ctx, param, value)``. This change was necessary as it15otherwise made reusing callbacks too complicated.1617To ease the transition Click will still accept old callbacks but it will18issue a warning to stderr to encourage you to upgrade.1920In case you want to support both Click 1.0 and Click 2.0 you can make a21simple decorator that adjusts the signatures::2223 import click24 from functools import update_wrapper2526 def compatcallback(f):27 # Click 1.0 does not have a version string stored, so we need to28 # use getattr here to be safe.29 if getattr(click, '__version__', '0.0') >= '2.0':30 return f31 return update_wrapper(lambda ctx, value: f(ctx, None, value), f)3233With that helper you can then write something like this::3435 @compatcallback36 def callback(ctx, param, value):37 return value.upper()3839Note that because Click 1.0 did not pass a parameter the `param` argument40here would be `None` so a compatibility callback could not use that41argument.