upgrading.rst
This file
Path
docs/upgrading.rst
43 lines · 1.5 KiB
Last changed by
Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
History of this fileTake it
Updated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 1–8why, one step back1Upgrading 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.8Added notes on callback changes to the docsArmin Ronacherbefore adoptiond27f3a6
lines 9–10why, one step back9.. _upgrade-to-2.0:10Updated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 11–15why, one step back11Upgrading 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)``Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
line 16why, one step back16whereas now it's ``(ctx, param, value)``. This change was necessary as itUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 17–18why, one step back17otherwise made reusing callbacks too complicated.18Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
line 19why, one step back19To ease the transition click will still accept old callbacks but it willUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 20–21why, one step back20issue a warning to stderr to encourage you to upgrade.21Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
line 22why, one step back22In case you want to support both click 1.0 and click 2.0 you can make aUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 23–40why, one step back23simple decorator that adjusts the signatures::2425 import click26 from functools import update_wrapper2728 def compatcallback(f):29 # Click 1.0 does not have a version string stored, so we need to30 # use getattr here to be safe.31 if getattr(click, '__version__', '0.0') >= '2.0':32 return f33 return update_wrapper(lambda ctx, value: f(ctx, None, value), f)3435With that helper you can then write something like this::3637 @compatcallback38 def callback(ctx, param, value):39 return value.upper()40Merge branch 'master' of https://github.com/mitsuhiko/clickArmin Ronacherbefore adoption8bd9f7a
line 41why, one step back41Note that because click 1.0 did not pass a parameter the `param` argumentUpdated docs for upgrade information.Armin Ronacherbefore adoptionebde9a0
lines 42–43why, one step back42here would be `None` so a compatibility callback could not use that43argument.