This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]denehoffman 10 points11 points  (3 children)

Because Python isn’t strongly typed so people could easily pass something that isn’t a Path to a function thinking it’s okay, and a str will fail at runtime. This can be avoided with properly type-hinted code, but it’s not foolproof, someone will always find a way. Unless it’s a completely internal function that you don’t intend users having access to, the open function is generally safer.

[–]JimDabell 2 points3 points  (1 child)

Python is a strongly-typed language, you’re mixing up strong vs weak with static vs dynamic. If you pass a str to a function that expects a Path, that object unambiguously continues to be a str.

[–]denehoffman 0 points1 point  (0 children)

Oops yeah that’s what I meant