Skip to content

Commit

Permalink
Moved content-type attribute deprecation warning to getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thetwam committed Apr 29, 2024
1 parent 66680c6 commit 583e9c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions canvasapi/canvas_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class CanvasObject(object):
"""

def __getattribute__(self, name):
if name == "content-type":
warnings.warn(
(
"The 'content-type' attribute will be removed "
"in a future version. Please use "
"'content_type' instead."
),
DeprecationWarning,
)
return super(CanvasObject, self).__getattribute__(name)

def __init__(self, requester, attributes):
Expand Down Expand Up @@ -64,14 +73,6 @@ def set_attributes(self, attributes):
self.__setattr__(attribute, value)
if attribute == "content-type":
self.__setattr__("content_type", value)
warnings.warn(
(
"The 'content-type' attribute will be removed "
"in a future version. Please use "
"'content_type' instead."
),
UserWarning,
)

try:
naive = arrow.get(str(value)).datetime
Expand Down
2 changes: 1 addition & 1 deletion tests/test_canvas_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_set_attributes_with_content_type_reversed(self, m):
self.assertTrue(hasattr(self.canvas_object, "filename"))
self.assertEqual(self.canvas_object.filename, "example.json")

def test__getattribute__content_type(self, m):
def test__getattribute__content_type_warns(self, m):
attributes = {"content-type": "application/json"}
self.canvas_object.set_attributes(attributes)

Expand Down

0 comments on commit 583e9c3

Please sign in to comment.