Opened 9 years ago

Closed 9 years ago

#5921 closed (wontfix)

Common parent class for User and AnonymousUser

Reported by: jag@… Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Howdy!

While I know of and respect Django's deference to Pythonic duck-typing, it would be helpful for isinstance(obj, klass) to confirm whether an object is a user or not, regardless of authentication. However User inherits solely from models.Model and AnonymousUser inherits from object -- they have no common lineage despite common interface.

This patch creates an abstract parent class for both User and AnonymousUser so a check for isinstance(obj, django.contrib.auth.models.UserClass) returns True whether the user is authenticated or not.

It provides this functionality without any other modification to the external interface, so there are no side-effects or other impacts of this change. I've tested it against the Django test suite and it passes.

-jag

Attachments (2)

common-parent-class-for-user-and-anonymoususer.patch (3.5 KB) - added by Joshua "jag" Ginsberg <jag@…> 9 years ago.
Patchfile
common-parent-class-for-user-and-anonymoususer.2.patch (2.1 KB) - added by Joshua "jag" Ginsberg <jag@…> 9 years ago.

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by Joshua "jag" Ginsberg <jag@…>

Patchfile

Changed 9 years ago by Joshua "jag" Ginsberg <jag@…>

comment:1 Changed 9 years ago by Joshua "jag" Ginsberg <jag@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Forgive my daftness -- the first patchfile was the wrong version and should be deleted from the ticket.

comment:2 Changed 9 years ago by Simon G <dev@…>

Summary: [PATCH] Common parent class for User and AnonymousUserCommon parent class for User and AnonymousUser
Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 9 years ago by Jacob

Resolution: wontfix
Status: newclosed

Generally we look down upon abstract base classes in Python and Django. That's especially true when the base class doesn't actually provide any functionality. So while I appreciate your desire to use isinstance/issubclass, this patch just doesn't fit.

Note: See TracTickets for help on using tickets.
Back to Top