Skip to content

Commit

Permalink
Warn about upcoming change of the centerOption (#313)
Browse files Browse the repository at this point in the history
* Added deprecate_kwarg decorator

* Added warning related to default centerOption deprecation
  • Loading branch information
adam-urbanczyk authored Apr 8, 2020
1 parent d17d27d commit 6ecb0fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
exporters,
)

from .utils import deprecate_kwarg


class CQContext(object):
"""
Expand Down Expand Up @@ -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
):
Expand Down
26 changes: 26 additions & 0 deletions cadquery/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6ecb0fc

Please sign in to comment.