Skip to content

Add file #5205

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Add file #5205

wants to merge 7 commits into from

Conversation

FlaveFlav20
Copy link

I created a file-like type for PyO3. Since file is a fundamental type in Python, I believe it should be supported by this library.

Example:

use pyo3::types::pyo3file::Pyo3File;

#[pyfunction]
fn my_custom_file(mut file: Pyo3File) -> PyResult<String> {
    let mut contents = String::new();

    file.getfile().read_to_string(&mut contents)?;

    Ok(contents)
}

I created a pyo3 type because the Python file uses three parameters that are not directly available in Rust::

  • name
  • opening mode
  • encoding (we can't know the file encoding with rust file type)

I opened this pull request to check if this approach is acceptable.

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.

1 participant