Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#27025 closed New feature (fixed)

Python 3.6 compatibility

Reported by: Tim Graham Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Python 3.6 final is scheduled for December 2016. This is a tracking ticket for compatibility fixes for Django submitted in the meantime.

Change History (31)

comment:1 by Tim Graham, 8 years ago

A couple failures bisected to the implementation of PEP 495 -- Local Time Disambiguation.

======================================================================
FAIL: test_localtime_naive (utils_tests.test_timezone.TimezoneTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/utils_tests/test_timezone.py", line 32, in test_localtime_naive
    timezone.localtime(datetime.datetime.now())
AssertionError: ValueError not raised

======================================================================
FAIL: test_make_naive (utils_tests.test_timezone.TimezoneTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/tests/utils_tests/test_timezone.py", line 140, in test_make_naive
    timezone.make_naive(datetime.datetime(2011, 9, 1, 13, 20, 30), EAT)
AssertionError: ValueError not raised

comment:2 by Aymeric Augustin, 8 years ago

Likely the time zone docs need some small additions to acknowledge the existence of PEP 495 -- even if the code can't rely on it until we drop support for Python < 3.6.

comment:3 by GitHub <noreply@…>, 8 years ago

In 35225e2a:

Refs #27025 -- Fixed a servers test on Python 3.6.

After https://hg.python.org/cpython/rev/4ea79767ff75/,
test_strips_underscore_headers fails with:
'Stub' object has no attribute 'sendall'.

comment:4 by GitHub <noreply@…>, 8 years ago

In a7a7ecd2:

Refs #27025 -- Fixed a couple timezone tests for Python 3.6.

Reflects behavior changes in PEP 495 (Local Time Disambiguation).

comment:5 by Tim Graham, 8 years ago

Django's test are passing with master @ 2b759c94c562c9ee9b6ca970739be15014050fda and cpython master @ 47f6c10084ed9aa8a08dbac20d5f6b814063c2df.

Version 0, edited 8 years ago by Tim Graham (next)

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

In 16202863:

Refs #27025 -- Fixed tests for the new ModuleNotFoundError in Python 3.6.

http://bugs.python.org/issue15767

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

In 49412f55:

Refs #27025 -- Fixed a test for the new re.RegexFlag in Python 3.6.

http://bugs.python.org/issue28082

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

In 8119b679:

Refs #27025 -- Fixed "invalid escape sequence" warnings in Python 3.6.

http://bugs.python.org/issue27364

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

In e43ea36:

Refs #27025 -- Fixed a timezone test for Python 3.6.

Reflects behavior changes in PEP 495 (Local Time Disambiguation).

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

In b5aac66b:

Refs #27025 -- Fixed ArrayField querying on Python 3.6.

Python 3.6 parses strings like '0_1' as numeric literals.
http://bugs.python.org/issue26331

comment:11 by Tim Graham, 8 years ago

I setup a more complete test environment that includes all of the test suite dependencies and identified a few more failures fixed in the above commits.

2 failures remain as of Django b5aac66b28c615b2bda63548cbd695dbb5a0c381 and cpython d614d687d9db1100d0a4ec8c67e0cb3ce773342b due to a sqlparse incompatibility with Python 3.6. I submitted a PR to fix it and it's merged awaiting the next release.

comment:12 by Tim Graham, 8 years ago

cpython fixed compatibility with sqlparse in https://hg.python.org/cpython/rev/1a2b8398f045/ so a new sqlparse release isn't needed and all tests are passing as of now.

comment:13 by Andrii Soldatenko, 8 years ago

just tested with last Django master e044026dce063ec53c16d0f755ec75eb8c84b318 and Python 3.6.0b4 works for me.
BTW where can I find how to add or check test results for Python3.6 and latest version of Django?
I see only Python3.5 http://djangoci.com/job/django-1.10/

Last edited 8 years ago by Andrii Soldatenko (previous) (diff)

comment:14 by Tim Graham, 8 years ago

I have a local Jenkins running with the cpython 3.6 branch and Django master that I check every couple days. I don't think we'll add Python 3.6 compatibility to older versions of Django such as 1.10 but we'll discuss it on the DevelopersMailingList if anyone feel it's important.

comment:15 by Anthony King, 8 years ago

py3.6 breaks calling super() (in the python3 style) inside Models with:
RuntimeError: super(): empty __class__ cell

This is also present on 1.8 and 1.10

class ModelToBreak(models.Model):
    def save(self, *args, **kwargs):
        return super().save(*args, **kwargs)
>>> m = ModelToBreak()
>>> m.save()
Traceback (most recent call last):
  File "/home/cybo/work/3.6-test/testing/d/tests.py", line 9, in test_empty_class_fail
    m.save()
  File "/home/cybo/work/3.6-test/testing/d/models.py", line 5, in save
    return super().save(*args, **kwargs)
RuntimeError: super(): empty __class__ cell

comment:16 by Tim Graham, 8 years ago

Thanks, the relevant commit in cpython is https://hg.python.org/cpython/rev/feb1ae9d5381.

I'm not sure if Django or cpython is at fault.

comment:17 by Tim Graham, 8 years ago

After some discussion on the cpython issue, I've created a PR to address the issue, but cpython may also restore backwards-compatibility and add a deprecation path.

comment:18 by Anthony King, 8 years ago

Thanks. I'll check all other MetaClasses for similar behaviour today or tomorrow.
Will also add Py3 tests for them.

comment:19 by Tim Graham, 8 years ago

I'm not particularly worried about tests since cpython added a deprecation path. Also, when we drop Python 2 compatibility in master in January, we'll probably change all super() calls to the new style.

comment:20 by GitHub <noreply@…>, 8 years ago

In dd99e69f:

Refs #27025 -- Fixed Python 3.6 deprecation warning for empty model super() calls.

https://bugs.python.org/issue23722

Thanks Nick Coghlan for advice and review.

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

In 4701abd5:

Refs #27025 -- Documented Python 3.6 compatibility for Django 1.11.

comment:22 by Tim Graham, 8 years ago

Resolution: fixed
Status: newclosed

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

In 72be3152:

Refs #27025 -- Added Python 3.6 to tox.ini.

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

In d4d79d0f:

Refs #27025 -- Fixed "invalid escape sequence" warning in auth_tests on Python 3.6.

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

In e34cce79:

[1.11.x] Refs #27025 -- Fixed "invalid escape sequence" warning in auth_tests on Python 3.6.

Backport of d4d79d0f200357b28419203557cc61c8168316ab from master

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

In f0ffa3f4:

Refs #27025, #28593 -- Fixed "invalid escape sequence" warnings in urls/resolvers.py.

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

In 5091bb6:

[2.0.x] Refs #27025, #28593 -- Fixed "invalid escape sequence" warnings in urls/resolvers.py.

Backport of f0ffa3f4ea277f9814285085fde20baff60fc386 from master

comment:28 by Jeroen Pulles, 7 years ago

Would it be possible to backport dd99e69fa8f89263d0396f23e0db9aa8fa667b01 (metaclass magic) to Django 1.8?

I'm seeing quite a few warnings for this, hiding the more useful warnings...

comment:29 by Tim Graham, 7 years ago

No, Django 1.8 doesn't have official support for Python 3.6 and only receives data loss and security fixes its end-of-life in April 2018.

Perhaps you can use warnings.filterwarnings() to hide the warnings.

comment:30 by Jeroen Pulles, 7 years ago

Okay. For the record: Adding this snippet to my development settings in my otherwise meta-class-free project, works for me:

import warnings
warnings.filterwarnings(
    action="ignore", 
    message=".*Was __classcell__ propagated to type[.]__new__.*")

comment:31 by GitHub <noreply@…>, 6 years ago

In 717ee63e:

Refs #27025 -- Removed obsolete sqlite3 transaction management workaround for Python 3.6+.

Obsolete per https://bugs.python.org/issue10740#msg274816.

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