mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #24205 -- Removed Signal.disconnect()'s weak argument.
Per deprecation timeline.
This commit is contained in:
		| @@ -1,10 +1,8 @@ | |||||||
| import warnings |  | ||||||
| from functools import partial | from functools import partial | ||||||
|  |  | ||||||
| from django.db.models.utils import make_model_tuple | from django.db.models.utils import make_model_tuple | ||||||
| from django.dispatch import Signal | from django.dispatch import Signal | ||||||
| from django.utils import six | from django.utils import six | ||||||
| from django.utils.deprecation import RemovedInDjango20Warning |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class_prepared = Signal(providing_args=["class"]) | class_prepared = Signal(providing_args=["class"]) | ||||||
| @@ -32,9 +30,7 @@ class ModelSignal(Signal): | |||||||
|             weak=weak, dispatch_uid=dispatch_uid, |             weak=weak, dispatch_uid=dispatch_uid, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|     def disconnect(self, receiver=None, sender=None, weak=None, dispatch_uid=None, apps=None): |     def disconnect(self, receiver=None, sender=None, dispatch_uid=None, apps=None): | ||||||
|         if weak is not None: |  | ||||||
|             warnings.warn("Passing `weak` to disconnect has no effect.", RemovedInDjango20Warning, stacklevel=2) |  | ||||||
|         return self._lazy_method( |         return self._lazy_method( | ||||||
|             super(ModelSignal, self).disconnect, apps, receiver, sender, dispatch_uid=dispatch_uid |             super(ModelSignal, self).disconnect, apps, receiver, sender, dispatch_uid=dispatch_uid | ||||||
|         ) |         ) | ||||||
|   | |||||||
| @@ -1,10 +1,8 @@ | |||||||
| import sys | import sys | ||||||
| import threading | import threading | ||||||
| import warnings |  | ||||||
| import weakref | import weakref | ||||||
|  |  | ||||||
| from django.utils import six | from django.utils import six | ||||||
| from django.utils.deprecation import RemovedInDjango20Warning |  | ||||||
| from django.utils.inspect import func_accepts_kwargs | from django.utils.inspect import func_accepts_kwargs | ||||||
| from django.utils.six.moves import range | from django.utils.six.moves import range | ||||||
|  |  | ||||||
| @@ -126,7 +124,7 @@ class Signal(object): | |||||||
|                 self.receivers.append((lookup_key, receiver)) |                 self.receivers.append((lookup_key, receiver)) | ||||||
|             self.sender_receivers_cache.clear() |             self.sender_receivers_cache.clear() | ||||||
|  |  | ||||||
|     def disconnect(self, receiver=None, sender=None, weak=None, dispatch_uid=None): |     def disconnect(self, receiver=None, sender=None, dispatch_uid=None): | ||||||
|         """ |         """ | ||||||
|         Disconnect receiver from sender for signal. |         Disconnect receiver from sender for signal. | ||||||
|  |  | ||||||
| @@ -145,8 +143,6 @@ class Signal(object): | |||||||
|             dispatch_uid |             dispatch_uid | ||||||
|                 the unique identifier of the receiver to disconnect |                 the unique identifier of the receiver to disconnect | ||||||
|         """ |         """ | ||||||
|         if weak is not None: |  | ||||||
|             warnings.warn("Passing `weak` to disconnect has no effect.", RemovedInDjango20Warning, stacklevel=2) |  | ||||||
|         if dispatch_uid: |         if dispatch_uid: | ||||||
|             lookup_key = (dispatch_uid, _make_id(sender)) |             lookup_key = (dispatch_uid, _make_id(sender)) | ||||||
|         else: |         else: | ||||||
|   | |||||||
| @@ -233,3 +233,6 @@ These features have reached the end of their deprecation cycle and are removed | |||||||
| in Django 2.0. See :ref:`deprecated-features-1.9` and | in Django 2.0. See :ref:`deprecated-features-1.9` and | ||||||
| :ref:`deprecated-features-1.10` for details, including how to remove usage of | :ref:`deprecated-features-1.10` for details, including how to remove usage of | ||||||
| these features. | these features. | ||||||
|  |  | ||||||
|  | * The ``weak`` argument to ``django.dispatch.signals.Signal.disconnect()`` is | ||||||
|  |   removed. | ||||||
|   | |||||||
| @@ -277,8 +277,3 @@ arguments are as described in :meth:`.Signal.connect`. The method returns | |||||||
|  |  | ||||||
| The ``receiver`` argument indicates the registered receiver to disconnect. It | The ``receiver`` argument indicates the registered receiver to disconnect. It | ||||||
| may be ``None`` if ``dispatch_uid`` is used to identify the receiver. | may be ``None`` if ``dispatch_uid`` is used to identify the receiver. | ||||||
|  |  | ||||||
| .. deprecated:: 1.9 |  | ||||||
|  |  | ||||||
|     The ``weak`` argument is deprecated as it has no effect. It will be removed |  | ||||||
|     in Django 2.0. |  | ||||||
|   | |||||||
| @@ -1,24 +0,0 @@ | |||||||
| import warnings |  | ||||||
|  |  | ||||||
| from django.dispatch import Signal |  | ||||||
| from django.test import SimpleTestCase |  | ||||||
|  |  | ||||||
| a_signal = Signal(providing_args=['val']) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def receiver_1_arg(val, **kwargs): |  | ||||||
|     return val |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class DispatcherTests(SimpleTestCase): |  | ||||||
|  |  | ||||||
|     def test_disconnect_weak_deprecated(self): |  | ||||||
|         a_signal.connect(receiver_1_arg) |  | ||||||
|         with warnings.catch_warnings(record=True) as warns: |  | ||||||
|             warnings.simplefilter('always') |  | ||||||
|             a_signal.disconnect(receiver_1_arg, weak=True) |  | ||||||
|         self.assertEqual(len(warns), 1) |  | ||||||
|         self.assertEqual( |  | ||||||
|             str(warns[0].message), |  | ||||||
|             'Passing `weak` to disconnect has no effect.', |  | ||||||
|         ) |  | ||||||
		Reference in New Issue
	
	Block a user