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

FileIO.name property #9195

Open
FoamyGuy opened this issue Apr 21, 2024 · 1 comment
Open

FileIO.name property #9195

FoamyGuy opened this issue Apr 21, 2024 · 1 comment

Comments

@FoamyGuy
Copy link
Collaborator

I'm wondering how hard it would be to add support for the name property to FileIO (or wherever is appropriate for use with the built-in open())

Currently In CPython:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open("something.txt", "wb")
>>> f.name
'something.txt'

Currently In CircuitPython:

Adafruit CircuitPython 9.1.0-beta.1-2-g87a400aa1d on 2024-04-21; Adafruit Feather ESP32-S3 TFT with ESP32S3
>>> f = open("boot_out.txt", "rb")
>>> f.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TextIOWrapper' object has no attribute 'name'

I noticed this difference between CPython and CircuitPython while working on a files argument for requests.post() In CPython that argument supports a type of value that would rely on retrieving the name of an already opened file. I was unable to find a way to do that with circuitpython, but if some way does already exist that could be used for my purpose and it wouldn't be strictly necessary to add support for name, but perhaps still nice to match cpython more closely.

If there is interest in this functionality, and if adding support for this wouldn't be super challenging I'd be willing to give it a try. But I would probably need a point in the right direction within the core code for where to start looking to add it.

@tannewt
Copy link
Member

tannewt commented Apr 22, 2024

I think you'd need to add a property for it here:

STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = {

The property getter would read internal state for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants