Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible. #90922

Closed
Kuplynx mannequin opened this issue Feb 16, 2022 · 8 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@Kuplynx
Copy link
Mannequin

Kuplynx mannequin commented Feb 16, 2022

BPO 46766
Nosy @stevendaprano, @serhiy-storchaka, @tirkarthi, @Kuplynx

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2022-02-16.08:42:33.706>
created_at = <Date 2022-02-16.04:56:32.434>
labels = ['type-feature', 'library', '3.11']
title = 'Add a class for file operations so a syntax such as open("file.img", File.Write | File.Binary | File.Disk) is possible.'
updated_at = <Date 2022-02-17.01:12:34.820>
user = 'https://github.com/Kuplynx'

bugs.python.org fields:

activity = <Date 2022-02-17.01:12:34.820>
actor = 'isaacsjohnson22'
assignee = 'none'
closed = True
closed_date = <Date 2022-02-16.08:42:33.706>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2022-02-16.04:56:32.434>
creator = 'isaacsjohnson22'
dependencies = []
files = []
hgrepos = []
issue_num = 46766
keywords = []
message_count = 8.0
messages = ['413315', '413316', '413317', '413321', '413322', '413336', '413357', '413373']
nosy_count = 4.0
nosy_names = ['steven.daprano', 'serhiy.storchaka', 'xtreak', 'isaacsjohnson22']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46766'
versions = ['Python 3.11']

@Kuplynx
Copy link
Mannequin Author

Kuplynx mannequin commented Feb 16, 2022

I think it would be great for something like this to be with the IO module. It will improve code readability.

@Kuplynx Kuplynx mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir labels Feb 16, 2022
@Kuplynx
Copy link
Mannequin Author

Kuplynx mannequin commented Feb 16, 2022

I'm currently working on implementing this. It will probably be a few weeks.

@Kuplynx Kuplynx mannequin added type-feature A feature request or enhancement labels Feb 16, 2022
@stevendaprano
Copy link
Member

I'm sorry, I don't see why you think this will improve code readability. I also expect it will be harder to teach than the current code.

open("file.img", "wb") just needs the user to learn about reading and writing files, and the difference between binary and text files. It works the same way in probably dozens of different languages.

open("file.img", File.Write | File.Binary | File.Disk) needs the beginner to learn the same details, plus they have to learn about this mystery File object, classes, dot notation, | the bitwise-or operator, and how to import File from the io module.

My guess is that File.Write etc are just enums equivalent to strings 'w' and 'b', but what's File.Disk?

What else does this File object do?

@tirkarthi
Copy link
Member

This looks similar to a previous proposal

https://discuss.python.org/t/enum-for-open-modes/2445

@serhiy-storchaka
Copy link
Member

You can create a module on PyPI. If it becomes popular we could consider including in the stdlib.

@Kuplynx
Copy link
Mannequin Author

Kuplynx mannequin commented Feb 16, 2022

Well it wouldn't need to be imported. I was working on including it inside builtins like open(). It wouldn't be very convenient if it needed to be imported.

@stevendaprano
Copy link
Member

True, but you did say it would be with the io module in your original suggestion.

@Kuplynx
Copy link
Mannequin Author

Kuplynx mannequin commented Feb 17, 2022

Well that is how it works with open. It is implemented in the io module and added to builtins.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants