Opened 11 months ago

Closed 8 months ago

#34642 closed New feature (fixed)

File.open to support different encodings

Reported by: Tomasz Melcer Owned by: Yves Weissig
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Currently the 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.

Change History (17)

comment:1 by Tomasz Melcer, 11 months ago

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

comment:2 by David Sanders, 11 months ago

Resolution: wontfix
Status: newclosed

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.

comment:3 by Natalia Bidart, 11 months ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

Reopening and accepting since there seems to be a consensus in the developer forum.

comment:4 by Adam Johnson, 10 months ago

Resolution: wontfix
Status: closednew

comment:5 by SecondPort, 10 months ago

Last edited 10 months ago by SecondPort (previous) (diff)

comment:6 by Mariusz Felisiak, 10 months ago

Has patch: set
Needs tests: set
Owner: changed from nobody to SecondPort
Patch needs improvement: set
Status: newassigned

comment:7 by abdulrahman, 10 months ago

Hey,

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

comment:8 by Mariusz Felisiak, 9 months ago

Owner: SecondPort removed
Status: assignednew

comment:9 by Yves Weissig, 9 months ago

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

in reply to:  9 comment:10 by Mariusz Felisiak, 9 months ago

Replying to Yves Weissig:

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

Thanks, please do.

comment:11 by Yves Weissig, 9 months ago

Owner: set to Yves Weissig
Status: newassigned

comment:12 by Yves Weissig, 9 months ago

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

comment:13 by Yves Weissig, 9 months ago

The PR is now ready here.

comment:14 by David Smith, 9 months ago

Needs tests: unset
Patch needs improvement: unset

comment:15 by Mariusz Felisiak, 9 months ago

Needs documentation: set

comment:16 by Mariusz Felisiak, 8 months ago

Needs documentation: unset
Triage Stage: AcceptedReady for checkin

comment:17 by Mariusz Felisiak <felisiak.mariusz@…>, 8 months ago

Resolution: fixed
Status: assignedclosed

In 369b4982:

Fixed #34642 -- Added File.open() support for *args and kwargs.

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