python / typeshed

Collection of library stubs for Python, with static types
Other
4.3k stars 1.73k forks source link

`TarInfo.mtime` typing is stricter than required #12520

Closed ncoghlan closed 1 month ago

ncoghlan commented 1 month ago

The typeshed stub types TarInfo.mtime strictly as int (presumably because it gets initialised to 0 in the standard library code). The Python stdlib docs type it as int|float. The implementation does support float values in this field as it coerces with int() when serialising mtime to the tar archive field.

This isn't a blocker for anything (since type checkers can be satisfied by making the truncation explicit in the code setting the TarInfo.mtime field), but the discrepancy with the stdlib docs made the issue seem worth filing.

ncoghlan commented 1 month ago

I believe making the typeshed stub align with the stdlib docs is the right answer here, so I've submitted a PR for that.

srittau commented 1 month ago

For future reference: It's okay to just send PRs in straight-forward cases like this. We don't require an issue for each PR.

ncoghlan commented 1 month ago

Thanks.

In this case, I wasn't sure if I had diagnosed the problem properly, hence filing the issue first (it was only after writing it up clearly enough to file the issue that I became sufficiently convinced of my own reasoning to send the PR. In particular, realising that stub autogeneration would have emitted the stricter type due to the way the field is initialised).