Python Bindings: Provide a deprecated GncPriceDB.lookup_latest_before_t64.

To avoid breaking user scripts.
This commit is contained in:
John Ralls 2021-04-22 18:36:42 -07:00 committed by Robert Fewell
parent 87285f945e
commit 49102c7ac2
2 changed files with 36 additions and 5 deletions

View File

@ -8,6 +8,31 @@
# @ingroup python_bindings
from functools import wraps
import inspect
from warnings import warn_explicit, warn
# General purpose deprecation decorator. Lifted from
# https://gist.github.com/kgriffs/8202106
def deprecated(message):
'''
Flags a method as deprecated.
param message: Text emitted as part of warning. Include instructions to replace the deprecated function e.g. "use waldo_pepper() isnstead."
'''
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
warning_msg = 'Call to deprecated function {}. {}'.format(
func.__name__, message)
frame = inspect.current_frame().f_back
warn_explicit(message,
category=DeprecationWarnig,
filename=inspect.getfile(frame.f_code),
lineno=frame.f_lineno)
return func(*args, **kwargs)
return wrapper
return decorator
# use of is_new, force_new and ignore_lock is deprecated, use mode instead
# the following decorators enable backward compatibility for the deprecation period
@ -30,8 +55,7 @@ def deprecated_args_session(ignore_lock_or_mode=None, is_new=None,
if deprecation:
# if any(item in ("is_new", "ignore_lock", "force_new") for item in kwargs):
import warnings
warnings.warn(
warn(
"Use of ignore_lock, is_new or force_new arguments is deprecated. Use mode argument instead. Have a look at gnucash.SessionOpenMode.",
category=DeprecationWarning,
stacklevel=3
@ -65,4 +89,3 @@ def deprecated_args_session_begin(original_function):
mode = deprecated_args_session(ignore_lock_or_mode, is_new, force_new, mode, ignore_lock)
return(original_function(self, new_uri=new_uri, mode=mode))
return new_function

View File

@ -53,7 +53,8 @@ from gnucash.gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn
from gnucash.deprecation import (
deprecated_args_session,
deprecated_args_session_init,
deprecated_args_session_begin
deprecated_args_session_begin,
deprecated
)
try:
@ -502,6 +503,14 @@ class GncPriceDB(GnuCashCoreClass):
See also https://code.gnucash.org/docs/head/gnc-pricedb_8h.html
'''
@deprecated("Use gnc_pricedb_latest_before_t64")
def gnc_pricedb_lookup_latest_before_t64(self, commodity, currency, date):
return self.lookup_nearest_before_t64(commodit, currency,date)
GncPriceDB.add_method('gnc_pricedb_lookup_latest_before_t64', 'lookup_latest_before_t64')
GncPriceDB.lookup_latest_before_t64 = method_function_returns_instance(GncPriceDB.lookup_latest_before_t64, GncPrice)
GncPriceDB.add_methods_with_prefix('gnc_pricedb_')
PriceDB_dict = {
'lookup_latest' : GncPrice,
@ -514,7 +523,6 @@ methods_return_instance(GncPriceDB,PriceDB_dict)
GncPriceDB.get_prices = method_function_returns_instance_list(
GncPriceDB.get_prices, GncPrice )
class GncCommodity(GnuCashCoreClass): pass
class GncCommodityTable(GnuCashCoreClass):