← 返回首页
Misleading exception message from `pathlib.PurePath()` when mixing str and bytes arguments · Issue #103525 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Misleading exception message from pathlib.PurePath() when mixing str and bytes arguments #103525

New issue
New issue

Description

Since 6716254, attempting to create a pathlib.PurePath or Path object with mixed str and bytes arguments raises a TypeError (yay!) with a misleading message (booo!):

>>> import pathlib >>> pathlib.Path('foo', b'bar') TypeError: Can't mix strings and bytes in path components

This message implies that bytes are supported, as long as we don't mix them with strings. And yet when we try that:

>>> pathlib.Path(b'foo', b'bar') TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'bytes'

This message is better, and should be used in the former case.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    • Open in GitHub Copilot app

    Footer

    © 2026 GitHub, Inc.