From 583e9c33cd3541679de3e1d76b3082c47f56dca4 Mon Sep 17 00:00:00 2001 From: Matthew Emond Date: Mon, 29 Apr 2024 01:06:22 -0400 Subject: [PATCH] Moved content-type attribute deprecation warning to getter --- canvasapi/canvas_object.py | 17 +++++++++-------- tests/test_canvas_object.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/canvasapi/canvas_object.py b/canvasapi/canvas_object.py index 9fae89c8..54b6ed4e 100644 --- a/canvasapi/canvas_object.py +++ b/canvasapi/canvas_object.py @@ -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): @@ -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 diff --git a/tests/test_canvas_object.py b/tests/test_canvas_object.py index 61aee77a..bad1d599 100644 --- a/tests/test_canvas_object.py +++ b/tests/test_canvas_object.py @@ -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)