upgrading.rst
This file
Path
docs/upgrading.rst
44 lines · 1.5 KiB
Last changed by
Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
History of this fileTake it
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.89.. _upgrade-to-2.0:1011Upgrading to 2.012----------------1314Click 2.0 has one breaking change which is the signature for parameter15callbacks. Before 2.0, the callback was invoked with ``(ctx, value)``16whereas now it's ``(ctx, param, value)``. This change was necessary as it17otherwise made reusing callbacks too complicated.1819To ease the transition Click will still accept old callbacks. Starting20with Click 3.0 it will start to issue a warning to stderr to encourage you21to upgrade.2223In case you want to support both Click 1.0 and Click 2.0, you can make a24simple decorator that adjusts the signatures::2526 import click27 from functools import update_wrapper2829 def compatcallback(f):30 # Click 1.0 does not have a version string stored, so we need to31 # use getattr here to be safe.32 if getattr(click, '__version__', '0.0') >= '2.0':33 return f34 return update_wrapper(lambda ctx, value: f(ctx, None, value), f)3536With that helper you can then write something like this::3738 @compatcallback39 def callback(ctx, param, value):40 return value.upper()4142Note that because Click 1.0 did not pass a parameter, the `param` argument43here would be `None`, so a compatibility callback could not use that44argument.