#13080 closed Cleanup/optimization (fixed)
Documentation bug for Signal.connect
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | signals |
Cc: | real.human@…, mmitar@…, berker.peksag@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Signal.connect says about the optional sender keyword "Must either be of type Signal, or None to receive events from any sender", but actually sender can be any any python object.
Change History (11)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 years ago
See #13132 for a related issue that requires clarification when the documentation surrounding sender is updated.
follow-up: 7 comment:3 by , 14 years ago
Cc: | added |
---|
Actually, it can't be any python object. It seems to only work somewhat reliably with classes, and even then you might experience double registration which is why we have the dispatch_uid
argument. This seems buggy to me. It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems. It should work as specified, or not, and preferably with "any python object" as the docstrings indicate. This would make it possible to connect receiver functions to signals sent by specific model instances, or senders that have nothing to do with models at all using a string literal sender.
comment:4 by , 14 years ago
Type: | → Bug |
---|
comment:5 by , 14 years ago
Severity: | → Normal |
---|
comment:6 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:7 by , 12 years ago
Replying to mrmachine:
Actually, it can't be any python object. It seems to only work somewhat reliably with classes, and even then you might experience double registration which is why we have the
dispatch_uid
argument. This seems buggy to me. It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems. It should work as specified, or not, and preferably with "any python object" as the docstrings indicate. This would make it possible to connect receiver functions to signals sent by specific model instances, or senders that have nothing to do with models at all using a string literal sender.
It would be better, but it isn't practical. "It doesn't seem like a very good system if we have to provide a second argument to make it work if you happen to experience double registration problems" - the issue is that the identity of an object in python is basically its memory address. dispatch_uid is to provide a canonical, well-known name for the given receiver. If dispatch_uid is not given, then if receiver happens to be two different objects (as happens when the same module is imported with different pathing, or when the receiver is a dynamically-created function), then there isn't a practical way to know it's the same receiver.
Additionally, we settled on a const-string as the fallback because performance overhead in the signals system is critical. pre_init and post_init are fatally performance-sensitive design choices, and dominate any consideration of changes in signals. String comparison is the simplest way to perform the needed human-readable, performance-sensitive equality comparison.
comment:9 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|---|
Type: | Bug → Cleanup/optimization |
Version: | 1.2-beta → master |
To clarify: This is a comment about the docstring on Signal.connect, line 59 of django/dispatch/dispatcher.py
(Note for future reference -- if you're going to make a bug report, it helps to point out *where* the bug is)