{"id": 925677191, "node_id": "MDU6SXNzdWU5MjU2NzcxOTE=", "number": 289, "title": "Mypy fixes for rows_from_file()", "user": {"value": 857609, "label": "adamchainz"}, "state": "closed", "locked": 0, "assignee": null, "milestone": null, "comments": 3, "created_at": "2021-06-20T20:34:59Z", "updated_at": "2021-06-22T18:44:36Z", "closed_at": "2021-06-22T18:13:26Z", "author_association": "NONE", "pull_request": null, "body": "Following https://github.com/simonw/sqlite-utils/issues/279#issuecomment-864328927\r\n\r\nYou had two mypy errors.\r\n\r\nThe first:\r\n\r\n> sqlite_utils/utils.py:157: error: Argument 1 to \"BufferedReader\" has incompatible type \"BinaryIO\"; expected \"RawIOBase\"\r\n\r\nLooking at the `BufferedReader` docs, it seems to expect a `RawIOBase`, and this [has been copied into typeshed](https://github.com/python/typeshed/blob/9ec2f8712480c57353cea097a65d75a2c4ec1846/stdlib/io.pyi#L100). There may be scope to change how `BufferedReader` is documented and typed upstream, but for now it wouldn't be too bad to use a `typing.cast()`:\r\n\r\n```\r\n# Detect the format, then call this recursively\r\nbuffered = io.BufferedReader(\r\n cast(io.RawIOBase, fp), # Undocumented BufferedReader support for BinaryIO\r\n buffer_size=4096,\r\n)\r\n```\r\n\r\nThe second error seems to be flagging a legitimate bug in your code:\r\n\r\n> sqlite_utils/utils.py:163: error: Argument 1 to \"decode\" of \"bytes\" has incompatible type \"Optional[str]\"; expected \"str\"\r\n\r\nFrom your type hints, `encoding` may be `None`. In the CSV format block, you use `encoding or \"utf-8-sig\"` to set a default, maybe that's desirable in this case too?\r\n", "repo": {"value": 140912432, "label": "sqlite-utils"}, "type": "issue", "active_lock_reason": null, "performed_via_github_app": null, "reactions": "{\"url\": \"https://api.github.com/repos/simonw/sqlite-utils/issues/289/reactions\", \"total_count\": 1, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 1, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "draft": null, "state_reason": "completed"}