apache / apache/beam

pathlib.Path, PathLike and __fspath__ support (PEP 519)

Open
#20,580 0 comments 0 reactions 0 assignees View on GitHub
avro bug files io P3 parquet python tfrecord
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

It would be nice to support `pathlib.Path`-like objects, as per PEP 519: https://www.python.org/dev/peps/pep-0519/

Currently, the following fail with: `TypeError: file_path_prefix must be a string or ValueProvider;got PosixPath('/tmp/pytest-of-forge-00/pytest-0/test_ptransform_beam0/output0.txt') instead`

```

import pathlib

path = pathlib.Path('/path/to/home')
beam.io.WriteToText(path)

```

Raised by FileBasedSink:

```

class FileBasedSink(iobase.Sink):

  def __init__(self)
    if not isinstance(file_path_prefix,
((str, unicode), ValueProvider)):
raise TypeError(...)

```

It could be implemented by calling `os.fspath(file_path_prefix)`

Imported from Jira [BEAM-11135](https://issues.apache.org/jira/browse/BEAM-11135). Original Jira may contain additional context.
Reported by: conchylicultor.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.