Question Details

No question body available.

Tags

python python-3.x glob pathlib

Answers (1)

February 3, 2026 Score: 0 Rep: 17 Quality: Low Completeness: 60%

glob.glob() only accepts strings and does not support PurePath or Path objects, so the crash you’re seeing is expected behavior. PurePath is intentionally filesystem-agnostic, while glob is an older, string-based API that was never updated to work with pathlib types.

The clean solution when migrating is to switch fully to pathlib and use Path.glob() or Path.rglob() instead. You can still call expanduser() first, but once you actually want to resolve files on disk, you should be using a real Path, not PurePath. For example, expand the path, then glob using Path.

If you need to keep glob.glob() for now, the simplest fix is to convert the path back to a string at the boundary: call expanduser() on the Path, then pass str(path) into glob.glob(). This keeps your migration incremental without breaking existing behavior.