-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(mimetypes): allow functions working with files to accept Paths
#15071
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
Conversation
| def guess_extension(type: str, strict: bool = True) -> str | None: ... | ||
| def init(files: Sequence[str] | None = None) -> None: ... | ||
| def read_mime_types(file: str) -> dict[str, str] | None: ... | ||
| def init(files: Sequence[StrPath] | None = None) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.path.isfile accepts Paths
|
|
||
| inited: bool | ||
| knownfiles: list[str] | ||
| knownfiles: list[StrPath] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If init allows Paths, then knownfiles should allow them too:
| types_map: tuple[dict[str, str], dict[str, str]] | ||
| types_map_inv: tuple[dict[str, str], dict[str, str]] | ||
| def __init__(self, filenames: tuple[str, ...] = (), strict: bool = True) -> None: ... | ||
| def __init__(self, filenames: tuple[StrPath, ...] = (), strict: bool = True) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it just works.
As a side note -- is there a particular reason why init accepts a Sequence of names, but MimeTypes.__init__ only a tuple? I mean other than it being initialised that way. It's working with either tuple or list.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Thanks @srittau I'd also appreciate it if you had any insight on #15071 (comment)
|
|
Looking at the source (for 3.12), it should accept an Some annotations in typeshed are ancient, predating modern typing features and standards, or were not updated even if Python itself was updated ages ago. This particular annotation seems to exist since |
|
@srittau much appreciated! |
No description provided.