From 6ecb0fc96f2379fbfd8de7f5b935dd880be99047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Urba=C5=84czyk?= Date: Wed, 8 Apr 2020 08:20:13 +0200 Subject: [PATCH] Warn about upcoming change of the centerOption (#313) * Added deprecate_kwarg decorator * Added warning related to default centerOption deprecation --- cadquery/cq.py | 3 +++ cadquery/utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 cadquery/utils.py diff --git a/cadquery/cq.py b/cadquery/cq.py index a97f82140..d788d678a 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -33,6 +33,8 @@ exporters, ) +from .utils import deprecate_kwarg + class CQContext(object): """ @@ -305,6 +307,7 @@ def toOCC(self): return self.objects[0].wrapped + @deprecate_kwarg("centerOption", "ProjectedOrigin") def workplane( self, offset=0.0, invert=False, centerOption="CenterOfMass", origin=None ): diff --git a/cadquery/utils.py b/cadquery/utils.py new file mode 100644 index 000000000..9ced46078 --- /dev/null +++ b/cadquery/utils.py @@ -0,0 +1,26 @@ +from functools import wraps +from inspect import signature +from warnings import warn + + +class deprecate_kwarg: + def __init__(self, name, new_value): + + self.name = name + self.new_value = new_value + + def __call__(self, f): + @wraps(f) + def wrapped(*args, **kwargs): + + f_sig_bound = signature(f).bind(*args, **kwargs) + + if self.name not in f_sig_bound.kwargs: + warn( + f"Default walue of {self.name} will change in next relase to {self.new_value}", + FutureWarning, + ) + + return f(*args, **kwargs) + + return wrapped