{"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-509681590", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 509681590, "node_id": "MDEyOklzc3VlQ29tbWVudDUwOTY4MTU5MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-07-09T15:07:12Z", "updated_at": "2021-06-22T18:17:53Z", "author_association": "OWNER", "body": "Here's a magic incantation for generating types detected through running the tests with https://github.com/Instagram/MonkeyType\r\n\r\n```\r\npip install pytest-monkeytype\r\npytest --monkeytype-output=./monkeytype.sqlite3\r\nmonkeytype list-modules\r\nmonkeytype apply sqlite_utils.utils\r\nmonkeytype apply sqlite_utils.cli\r\nmonkeytype apply sqlite_utils.db\r\n```\r\n\r\nHere's the result: https://github.com/simonw/sqlite-utils/commit/d18c694fc25b7dd3d76e250c77ddf56d10ddf935", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-509685610", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 509685610, "node_id": "MDEyOklzc3VlQ29tbWVudDUwOTY4NTYxMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-07-09T15:16:52Z", "updated_at": "2019-07-09T15:16:52Z", "author_association": "OWNER", "body": "Also interesting:\r\n```\r\npip install pytest-mypy\r\npytest --mypy\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-509686432", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 509686432, "node_id": "MDEyOklzc3VlQ29tbWVudDUwOTY4NjQzMg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-07-09T15:18:49Z", "updated_at": "2019-07-09T15:18:49Z", "author_association": "OWNER", "body": "Interestingly if I run that against my `monkeytype` branch I get the following errors (subset):\r\n```\r\n_______________________________________________________________________________________ mypy db.py ________________________________________________________________________________________\r\nsqlite_utils/db.py:15: error: No library stub file for module 'numpy'\r\nsqlite_utils/db.py:15: note: (Stub files are from https://github.com/python/typeshed)\r\nsqlite_utils/db.py:197: error: Incompatible types in assignment (expression has type \"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], Dict[, ]]\", variable has type \"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], None]\")\r\nsqlite_utils/db.py:204: error: Item \"None\" of \"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], None]\" has no attribute \"__iter__\" (not iterable)\r\nsqlite_utils/db.py:206: error: Argument 1 to \"set\" has incompatible type \"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], None]\"; expected \"Iterable[str]\"\r\nsqlite_utils/db.py:211: error: Item \"None\" of \"Optional[Tuple[str, str, str]]\" has no attribute \"index\"\r\nsqlite_utils/db.py:211: error: Unsupported right operand type for in (\"Optional[Tuple[str, str, str]]\")\r\nsqlite_utils/db.py:232: error: Unsupported right operand type for in (\"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], None]\")\r\nsqlite_utils/db.py:234: error: Value of type \"Union[Dict[str, int], Dict[str, Union[int, str]], Dict[str, str], None]\" is not indexable\r\nsqlite_utils/db.py:307: error: Need type annotation for 'table_sql' (hint: \"table_sql: Dict[, ] = ...\")\r\nsqlite_utils/db.py:427: error: Item \"int\" of \"Union[int, None, str]\" has no attribute \"startswith\"\r\nsqlite_utils/db.py:427: error: Item \"None\" of \"Union[int, None, str]\" has no attribute \"startswith\"\r\nsqlite_utils/db.py:434: error: Incompatible types in assignment (expression has type \"List[Any]\", target has type \"int\")\r\nsqlite_utils/db.py:438: error: Incompatible types in assignment (expression has type \"object\", target has type \"int\")\r\nsqlite_utils/db.py:670: error: Need type annotation for 'all_column_types' (hint: \"all_column_types: Dict[, ] = ...\")\r\nsqlite_utils/db.py:757: error: Incompatible types in assignment (expression has type \"List[Any]\", variable has type \"chain[Any]\")\r\nsqlite_utils/db.py:761: error: Argument 1 to \"create\" of \"Table\" has incompatible type \"Dict[str, Union[Type[str], Type[int], Type[bool], Type[time], Type[float]]]\"; expected \"Dict[str, Union[Type[str], Type[int], Type[bool], Type[time]]]\"\r\nsqlite_utils/db.py:770: error: Need type annotation for 'all_columns' (hint: \"all_columns: Set[] = ...\")\r\nsqlite_utils/db.py:773: error: Incompatible types in assignment (expression has type \"List[Any]\", variable has type \"Set[Any]\")\r\nsqlite_utils/db.py:775: error: \"Set[Any]\" has no attribute \"insert\"\r\nsqlite_utils/db.py:797: error: Need type annotation for 'values' (hint: \"values: List[] = ...\")\r\nsqlite_utils/db.py:811: error: Argument 1 to \"add_missing_columns\" of \"Table\" has incompatible type \"chain[Any]\"; expected \"Union[List[Union[Dict[str, Union[int, str]], Dict[str, Union[int, str, List[str]]]]], List[Dict[str, Union[str, int, float]]], List[Dict[str, Union[int, str]]]]\"\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-868881033", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 868881033, "node_id": "MDEyOklzc3VlQ29tbWVudDg2ODg4MTAzMw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-25T23:23:49Z", "updated_at": "2021-06-25T23:23:49Z", "author_association": "OWNER", "body": "Twitter conversation about how to add types to the `.create_table(columns=)` parameter: https://twitter.com/simonw/status/1408532867592818693\r\n\r\n> Anyone know how to write a mypy type definition for this?\r\n>\r\n> {\"id\": int, \"name\": str, \"image\": bytes, \"weight\": float}\r\n>\r\n> It's a dict where keys are strings and values are one of int/str/bytes/float (weird API design I know, but I designed this long before I was thinking about mypy)\r\n\r\nLooks like this could work:\r\n\r\n```python\r\n def create_table(\r\n self,\r\n name,\r\n columns: Dict[str, Union[Type[int], Type[bytes], Type[str], Type[float]]],\r\n pk=None,\r\n foreign_keys=None,\r\n column_order=None,\r\n not_null=None,\r\n defaults=None,\r\n hash_id=None,\r\n extracts=None,\r\n ):\r\n```\r\nExcept... that method can optionally also accept `numpy` types if `numpy` is installed. I don't know if it's possible to dynamically change a signature based on an import, since `mypy` is a static type analyzer and doesn't ever execute the code.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-868881190", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 868881190, "node_id": "MDEyOklzc3VlQ29tbWVudDg2ODg4MTE5MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-25T23:24:28Z", "updated_at": "2021-06-25T23:24:28Z", "author_association": "OWNER", "body": "Maybe I could release a separate Python package `types-sqlite-utils-numpy` which adds an over-ridden type definition that includes the `numpy` types?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-901452199", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 901452199, "node_id": "IC_kwDOCGYnMM41uxGn", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-08-18T21:48:57Z", "updated_at": "2021-08-18T21:48:57Z", "author_association": "OWNER", "body": "I did a bunch of work on this in #266. The library is now pretty thoroughly typed, and I even found a couple of bugs using `mypy` along the way: #313 and #315.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null}