Opened 12 months ago

Closed 12 months ago

Last modified 6 weeks ago

#27546 closed Cleanup/optimization (fixed)

Replace hardcoded class names in __repr__-methods

Reported by: Mads Jensen Owned by: Adiyat Mubarak
Component: Core (Other) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I noticed there are a few places where __repr__ does not use self.__class__.__name__. I think this is a small clean-up that would make sense to do, but perhaps there was a good reason not to do that (probably they're never subclassed?). The following output is from grep:

django/db/models/query.py:        return "<RawQuerySet: %s>" % self.query
django/db/models/sql/query.py:        return "<RawQuery: %s>" % self
django/db/migrations/state.py:        return "<ModelState: '%s.%s'>" % (self.app_label, self.name)
django/utils/baseconv.py:        return "<BaseConverter: base%s (%s)>" % (len(self.digits), self.digits)
django/core/management/commands/makemessages.py:        return "<TranslatableFile: %s>" % os.sep.join([self.dirpath, self.file])
django/core/serializers/base.py:        return "<DeserializedObject: %s(pk=%s)>" % (

Change History (9)

comment:1 Changed 12 months ago by Tim Graham

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted

Sure, while there it would be nice to add tests if missing.

comment:2 Changed 12 months ago by Adiyat Mubarak

Owner: changed from nobody to Adiyat Mubarak
Status: newassigned

comment:3 in reply to:  description Changed 12 months ago by Adiyat Mubarak

Replying to Mads Jensen:

I noticed there are a few places where __repr__ does not use self.__class__.__name__. I think this is a small clean-up that would make sense to do, but perhaps there was a good reason not to do that (probably they're never subclassed?). The following output is from grep:

django/db/models/query.py:        return "<RawQuerySet: %s>" % self.query
django/db/models/sql/query.py:        return "<RawQuery: %s>" % self
django/db/migrations/state.py:        return "<ModelState: '%s.%s'>" % (self.app_label, self.name)
django/utils/baseconv.py:        return "<BaseConverter: base%s (%s)>" % (len(self.digits), self.digits)
django/core/management/commands/makemessages.py:        return "<TranslatableFile: %s>" % os.sep.join([self.dirpath, self.file])
django/core/serializers/base.py:        return "<DeserializedObject: %s(pk=%s)>" % (

Hi, I just learn to contribute on django project by taking this easy task on this PR
Do I need to update this ticket to resolve as fixed? or this ticket will closed automatically?

Thank in advance

comment:4 Changed 12 months ago by Adiyat Mubarak

Has patch: set

comment:5 Changed 12 months ago by Mads Jensen

Ticket will be closed when a maintainer merges the changes and marks it as solved.

comment:6 Changed 12 months ago by Tim Graham <timograham@…>

In 794b7d80:

Refs #27546 -- Tested some repr() methods.

comment:7 Changed 12 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 48826aa:

Fixed #27546 -- Removed hardcoded class names in repr() methods.

comment:8 Changed 10 months ago by Tim Graham <timograham@…>

In 86ae1d51:

Refs #27546 -- Removed hardcoded class names in repr() methods.

comment:9 Changed 6 weeks ago by Tim Graham <timograham@…>

In ee7ab1b6:

Refs #27546 -- Replaced hardcoded class name in ForNode.repr().

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