Skip to content

Comments

Migrate Booktype to Python 3#928

Draft
Copilot wants to merge 6 commits intomasterfrom
copilot/migrate-booktype-to-python3
Draft

Migrate Booktype to Python 3#928
Copilot wants to merge 6 commits intomasterfrom
copilot/migrate-booktype-to-python3

Conversation

Copy link

Copilot AI commented Feb 13, 2026

Migrates codebase from Python 2 to Python 3.6+. Updates Django from 1.11 to 2.2 LTS and modernizes dependencies.

Dependency Updates

  • Python 3.6+ with Django 2.2 LTS (minimum Python 3 compatible Django)
  • Updated dependencies: djangorestframework 3.11+, celery 4.4+, redis 3.0+, Pillow 6.0+
  • Replaced django-rest-swagger → drf-yasg, BeautifulSoup → beautifulsoup4
  • Removed simplejson (native json module)

Django 2.0+ Compatibility

  • All __unicode__()__str__() in models (18 classes)
  • Added on_delete=models.CASCADE to ForeignKey fields (59 fields)

Python 3 Syntax

  • Imports: urllib2urllib.request, urlparseurllib.parse, StringIOio.StringIO
  • Exception handling: except E, e:except E as e:
  • Dict methods: .iteritems().items(), .has_key(x)x in dict
  • Type checks: unicode()str(), basestringstr
  • Print statements → print functions
  • Renamed async variables (reserved keyword in Python 3.5+)
  • Fixed lambda tuple unpacking: lambda (a, b):lambda item: ... item[0] ... item[1]

String/Bytes Handling

# Before (Python 2)
f = open('file.txt', 'r')
content = str(f.read(), 'utf-8')

# After (Python 3)
with open('file.txt', 'r', encoding='utf-8') as f:
    content = f.read()

All 387 Python files compile successfully with Python 3.12.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 13, 2026 22:57
…lity

- Update setup.py to specify Python 3.6+ support
- Update Django from 1.11 to 2.2 LTS (Python 3 compatible)
- Update all dependencies to Python 3 compatible versions
- Replace __unicode__ with __str__ in all models
- Fix Python 2 imports (urllib2, urlparse, StringIO) to Python 3 equivalents
- Convert print statements to print() functions

Co-authored-by: eos87 <124766+eos87@users.noreply.github.com>
- Replace dict.iteritems/iterkeys/itervalues with items/keys/values
- Replace unicode() calls with str()
- Replace basestring with str
- Fix except statements from 'except E, e:' to 'except E as e:'
- Replace dict.has_key(x) with 'x in dict'
- Update json_wrapper to use standard json module

Co-authored-by: eos87 <124766+eos87@users.noreply.github.com>
- Fix broken print statement continuation in permissions.py
- Replace 'async' variable name with 'task' (async is a reserved keyword in Python 3.5+)
- Fix lambda tuple unpacking in filter functions (not supported in Python 3)
- Wrap filter() results with list() for Python 3 compatibility

Co-authored-by: eos87 <124766+eos87@users.noreply.github.com>
…atibility

Django 2.0 requires on_delete parameter for all ForeignKey fields.
Added on_delete=models.CASCADE to all ForeignKey fields in models.

Co-authored-by: eos87 <124766+eos87@users.noreply.github.com>
- Fix file reading to use encoding parameter in open() instead of str()
- Fix wordcount functions to check for bytes instead of str
- Add BytesIO import and use it for binary data
- Fix unicode type checks to use bytes checks
- Fix json.dumps() usage (returns str in Python 3, not bytes)
- Add None check before calling startswith() on filter lambda

Co-authored-by: eos87 <124766+eos87@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate booktype codebase to Python 3 Migrate Booktype to Python 3 Feb 13, 2026
Copilot AI requested a review from eos87 February 13, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants