Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise deprecation warning only when attribute is accessed #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions braintree/dispute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from braintree.dispute_details import DisputeEvidence, DisputeStatusHistory, DisputePayPalMessage
from braintree.configuration import Configuration

class Dispute(AttributeGetter):

class _DisputeType(type):
@property
def ChargebackProtectionLevel(cls):
warnings.warn("Use ProtectionLevel enum instead", DeprecationWarning)
return cls._ChargebackProtectionLevel


class Dispute(AttributeGetter, metaclass=_DisputeType):
# NEXT_MAJOR_VERSION this can be an enum! they were added as of python 3.4 and we support 3.5+
class Status(object):
"""
Expand Down Expand Up @@ -72,19 +80,22 @@ class Kind(object):
Retrieval = "retrieval"

# NEXT_MAJOR_VERSION Remove this enum
class ChargebackProtectionLevel(object):
class _ChargebackProtectionLevel(object):
"""
Constants representing dispute ChargebackProtectionLevel. Available types are:

* braintree.Dispute.ChargebackProtectionLevel.EFFORTLESS
* braintree.Dispute.ChargebackProtectionLevel.STANDARD
* braintree.Dispute.ChargebackProtectionLevel.NOT_PROTECTED
"""
warnings.warn("Use ProtectionLevel enum instead", DeprecationWarning)
Effortless = "effortless"
Standard = "standard"
NotProtected = "not_protected"

@property
def ChargebackProtectionLevel(self):
return self.__class__.ChargebackProtectionLevel

# NEXT_MAJOR_VERSION this can be an enum! they were added as of python 3.4 and we support 3.5+
class PreDisputeProgram(object):
"""
Expand Down
16 changes: 14 additions & 2 deletions braintree/dispute_search.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import warnings

from braintree.search import Search

class DisputeSearch:

class _DisputeSearchType(type):
@property
def chargeback_protection_level(cls):
warnings.warn("Use protection_level parameter instead", DeprecationWarning)
return cls._chargeback_protection_level


class DisputeSearch(metaclass=_DisputeSearchType):
amount_disputed = Search.RangeNodeBuilder("amount_disputed")
amount_won = Search.RangeNodeBuilder("amount_won")
case_number = Search.TextNodeBuilder("case_number")
# NEXT_MAJOR_VERSION Remove this attribute
# DEPRECATED The chargeback_protection_level attribute is deprecated in favor of protection_level
chargeback_protection_level = Search.MultipleValueNodeBuilder("chargeback_protection_level")
with warnings.catch_warnings():
warnings.simplefilter('ignore')
_chargeback_protection_level = Search.MultipleValueNodeBuilder("chargeback_protection_level")
protection_level = Search.MultipleValueNodeBuilder("protection_level")
customer_id = Search.TextNodeBuilder("customer_id")
disbursement_date = Search.RangeNodeBuilder("disbursement_date")
Expand Down