[Django] #34642: File.open to support different encodings

5 views
Skip to first unread message

Django

unread,
Jun 8, 2023, 6:15:06 AM6/8/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
----------------------------------------+------------------------
Reporter: liori | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Currently the
[https://github.com/django/django/blob/main/django/core/files/base.py#L108
File.open] method has only a single parameter `mode`. `mode` can suggest
opening a file in text mode. Then, Python's `open` will by default attempt
to use the common utf-8 encoding.

It is a common pattern in a code base I work on to use the `utf-8-sig`
encoding for CSV files, as this provides a slight improvement to user
experience when opening the file in Excel. Right now, to create a file in
this encoding using Django's File, we have to open it in a binary mode and
explicitly wrap the file handle in a codec. It would be helpful if, just
like the base Python's `open` function, `File.open` also accepted an
`encoding` parameter, and pass it to the Python's `open` function.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 8, 2023, 6:19:43 AM6/8/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
------------------------------+--------------------------------------

Reporter: liori | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by liori):

I am willing to work in this feature, I'd like to just know whether it be
considered for addition to the project?

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:1>

Django

unread,
Jun 8, 2023, 9:49:35 PM6/8/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+--------------------------------------
Reporter: Tomasz Melcer | Owner: nobody
Type: New feature | Status: closed

Component: Core (Other) | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by David Sanders):

* status: new => closed
* resolution: => wontfix


Comment:

Hi Tomasz,

Sounds like a good idea, though…

Not many people will see feature requests on the issue tracker so people
are encouraged to start discussion in the Django forum first:
https://code.djangoproject.com/wiki/DevelopersMailingList. This way more
people will see the request & respond. One thing that comes to mind is
that the `File` class could pass through `*args, **kwargs` to the `open()`
function to avoid gatekeeping, though not sure whether this was
intentional or not 🤔

The procedure is to close the ticket as "wontfix" pending further
discussion on the forum, we can reopen when a decision is made to proceed.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:2>

Django

unread,
Jun 19, 2023, 9:04:18 AM6/19/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: nobody
Type: New feature | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Natalia Bidart):

* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Reopening and accepting since there seems to be a consensus in the
[https://forum.djangoproject.com/t/file-open-to-support-different-
encodings/21491 developer forum].

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:3>

Django

unread,
Jun 23, 2023, 2:17:21 AM6/23/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: nobody
Type: New feature | Status: new

Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Adam Johnson):

* status: closed => new
* resolution: wontfix =>


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:4>

Django

unread,
Jun 23, 2023, 10:25:23 PM6/23/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by SecondPort):

i will work on this

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:5>

Django

unread,
Jun 24, 2023, 3:27:07 AM6/24/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+--------------------------------------
Reporter: Tomasz Melcer | Owner: SecondPort
Type: New feature | Status: assigned

Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => SecondPort
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* status: new => assigned
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:6>

Django

unread,
Jun 29, 2023, 6:09:06 PM6/29/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+--------------------------------------
Reporter: Tomasz Melcer | Owner: SecondPort
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by abdulrahman):

Hey,

I can take this ticket if no one has time for it, I had to use
io.TextIOWrapper to use a different encoding.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:7>

Django

unread,
Aug 1, 2023, 8:06:52 AM8/1/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: (none)

Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: SecondPort => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:8>

Django

unread,
Aug 2, 2023, 3:11:09 AM8/2/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: (none)
Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Yves Weissig):

If there are no other takers I'm happy to clean up the patch and write
tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:9>

Django

unread,
Aug 2, 2023, 3:43:16 AM8/2/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+------------------------------------
Reporter: Tomasz Melcer | Owner: (none)
Type: New feature | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:9 Yves Weissig]:


> If there are no other takers I'm happy to clean up the patch and write
tests.

Thanks, please do.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:10>

Django

unread,
Aug 2, 2023, 6:20:54 AM8/2/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+----------------------------------------
Reporter: Tomasz Melcer | Owner: Yves Weissig

Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by Yves Weissig):

* owner: (none) => Yves Weissig


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:11>

Django

unread,
Aug 16, 2023, 2:39:42 AM8/16/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+----------------------------------------
Reporter: Tomasz Melcer | Owner: Yves Weissig
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+----------------------------------------

Comment (by Yves Weissig):

Just a quick update, I'm on it, PR will follow shortly.

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:12>

Django

unread,
Aug 18, 2023, 1:27:24 PM8/18/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+----------------------------------------
Reporter: Tomasz Melcer | Owner: Yves Weissig
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+----------------------------------------

Comment (by Yves Weissig):

The PR is now ready [https://github.com/django/django/pull/17173 here].

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:13>

Django

unread,
Aug 18, 2023, 1:50:25 PM8/18/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+----------------------------------------
Reporter: Tomasz Melcer | Owner: Yves Weissig
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by David Smith):

* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:14>

Django

unread,
Aug 19, 2023, 9:30:12 AM8/19/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------+----------------------------------------
Reporter: Tomasz Melcer | Owner: Yves Weissig
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+----------------------------------------
Changes (by Mariusz Felisiak):

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:15>

Django

unread,
Sep 11, 2023, 12:10:30 AM9/11/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------------+-------------------------------------

Reporter: Tomasz Melcer | Owner: Yves
| Weissig
Type: New feature | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:16>

Django

unread,
Sep 11, 2023, 2:10:05 AM9/11/23
to django-...@googlegroups.com
#34642: File.open to support different encodings
-------------------------------------+-------------------------------------
Reporter: Tomasz Melcer | Owner: Yves
| Weissig
Type: New feature | Status: closed

Component: Core (Other) | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"369b498219be791ebec8233208f08f07621b8359" 369b4982]:
{{{
#!CommitTicketReference repository=""
revision="369b498219be791ebec8233208f08f07621b8359"
Fixed #34642 -- Added File.open() support for *args and **kwargs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:17>

Reply all
Reply to author
Forward
0 new messages