Skip to content

Improve typing for import_from_yaml and export_to_yaml#134

Open
Morwenn wants to merge 2 commits into
AlexandreDecan:masterfrom
Morwenn:import-from-yaml-more-permissive-typing
Open

Improve typing for import_from_yaml and export_to_yaml#134
Morwenn wants to merge 2 commits into
AlexandreDecan:masterfrom
Morwenn:import-from-yaml-more-permissive-typing

Conversation

@Morwenn

@Morwenn Morwenn commented Jul 15, 2026

Copy link
Copy Markdown

Hi, thanks for the great library.

I regularly need to send pathlike.Path objects to the filepath parameter of import_from_yaml. It does already work correctly because filepath is simply forwarded to open, but it breaks the typing, forcing me to either use #type: ignore or to convert the path to a string explicitly, which becomes a bit noisy when there's many occurrences.

This MR changes the expected type of filepath from str to Union[str, bytes, os.PathLike], mirroring what open accepts.

I modified export_to_yaml as a drive-by fix for consistency, since it also just forwards its parameter to open.

@AlexandreDecan

Copy link
Copy Markdown
Owner

Hello,

Thanks for the suggested change and the explanations. Are there other places where a filepath is expected and accepting a Path object makes sense? Could you check and apply your change, so that we uniformly and consistently accept Path objects as well?

Thanks!

@Morwenn

Morwenn commented Jul 15, 2026

Copy link
Copy Markdown
Author

I searched for all instances of open( in the library, and could only find export_to_plantuml that warranted a similar changed. Which I applied accordingly.

@AlexandreDecan

Copy link
Copy Markdown
Owner

Thanks, I'll also check on my side (I think there are a few other places where we support file paths such as in the bdd cli). I'll be away for a few days so don't worry if this pr remains open for now :-)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants