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 support for pathlib #114

Open
pauloxnet opened this issue Nov 7, 2021 · 5 comments
Open

Add support for pathlib #114

pauloxnet opened this issue Nov 7, 2021 · 5 comments

Comments

@pauloxnet
Copy link

It would be great to add the ability to read file path as pathlib.Path.

@kthy
Copy link
Contributor

kthy commented Nov 8, 2021

I just tried this:

import pathlib
import polib
pth = pathlib.Path(r"C:\whatever\sample.po")
pofile = polib.pofile(pth)
for entry in pofile:
    print(entry.msgid, entry.msgstr)

Worked fine in Python 3.9. Is there anything you've found to not Just Work™ with pathlib?

@pauloxnet
Copy link
Author

I just tried this:

import pathlib
import polib
pth = pathlib.Path(r"C:\whatever\sample.po")
pofile = polib.pofile(pth)
for entry in pofile:
    print(entry.msgid, entry.msgstr)

Good to know, this can be the first test to add.

Worked fine in Python 3.9. Is there anything you've found to not Just Work™ with pathlib?

There's no info about pathlib in the README or in the docs and there aren't tests that can guarantee that polib will works with pathlib in the future.

@izimobil
Copy link
Owner

izimobil commented Nov 8, 2021

AFAIK, pathlib is just for manipulating pathes in an object oriented way, in the end it is evaluated as a string, and it is backward compatible with the os.path module.

So:

  • I don't think there's any need to document this (I doubt every single python library that uses builtin open function, will mention pathlib support, as open already supports pathlib)
  • A unit test wouldn't hurt maybe (for example if in the future polib makes decision based on the type of given path) but it's not really necessary as for now.

@tosky
Copy link

tosky commented Apr 10, 2022

Hi,
I think there is just a use case why to officially document the support: right now the (3rd-party, but very useful) types-polib library (https://pypi.org/project/types-polib/) follows the official definition and when a type checker like mypy is executed against a a simple code like
potfile.save(pathlib_obj)
where pathlib_obj is a pathlib.Path, the check fails.
If the pathlib support was officially documented, it would be possible to ask types-polib maintainers to declare the support without having to exclude polib+pathlib usages from type checkers. I'm not sure types-polib would accept a change like this without official support, but to be honest I haven't asked.

@m-aciek
Copy link

m-aciek commented Jan 23, 2025

types-polib package is built from typeshed project. I've added a PR with support for Path in pofile() function recently.

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

No branches or pull requests

5 participants