Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#19539 closed Cleanup/optimization (fixed)

Writing custom model fields: The __metaclass__ attribute is no longer supported in Python 3

Reported by: astorije@… Owned by: nobody
Component: Documentation Version: 1.5-alpha-1
Severity: Normal Keywords:
Cc: 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

As Django 1.5 introduces the support of Python 3, I think the documentation of "Writing custom model fields" should warn developers that:

class MyCustomField(models.Field):
    __metaclass__ = models.SubfieldBase

is no longer supported and that they should use:

class MyCustomField(models.Field, metaclass=models.SubfieldBase):
    ...

instead.

Writing in the first (old) fashion results in no errors or warnings whatsoever. The to_python() method is just not called as it should be...

Attachments (1)

19539.diff (1.2 KB ) - added by Tim Graham 11 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Aymeric Augustin, 12 years ago

The second version isn't acceptable as is because it's a syntax error under Python 2. If you want a single snippet that works in Python 2 and 3 you have to use six.with_metaclass.

Currently the documentation assumes Python 2. We haven't chosen how to document things that are different in Python 2 and 3 yet.

Technically, this ticket is valid, but it covers about 0.1% of the problem. For starters, the docs has tons of __unicode__ methods that don't make any sense under Python 3...

comment:2 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed
Type: UncategorizedNew feature

comment:3 by Aymeric Augustin, 12 years ago

Triage Stage: Design decision neededAccepted

We'll have to fix this at some point.

by Tim Graham, 11 years ago

Attachment: 19539.diff added

comment:4 by Tim Graham, 11 years ago

Has patch: set

comment:5 by Claude Paroz, 11 years ago

Triage Stage: AcceptedReady for checkin
Type: New featureCleanup/optimization

comment:6 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In b9fceadfd440daec09dee3c7c9d01997f94ec94f:

Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.

comment:7 by Tim Graham <timograham@…>, 11 years ago

In 6c984587711f82c0fc5223bbf6e8bb3b71732a3e:

[1.5.x] Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.

Backport of b9fceadfd4 from master.

comment:8 by Tim Graham <timograham@…>, 11 years ago

In 14a5b79e294506ab045a14fbec89030510f1cefe:

[1.6.x] Fixed #19539 -- Updated custom model fields example for Python 3.

Thanks astorije@ for the report.

Backport of b9fceadfd4 from master.

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