{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/2096","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/2096/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/2096/comments","events_url":"https://api.github.com/repos/python/mypy/issues/2096/events","html_url":"https://github.com/python/mypy/issues/2096","id":175000217,"number":2096,"title":"A story: Getting started with mypy on a large existing codebase","user":{"login":"davidfstr","id":764688,"avatar_url":"https://avatars.githubusercontent.com/u/764688?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfstr","html_url":"https://github.com/davidfstr","followers_url":"https://api.github.com/users/davidfstr/followers","following_url":"https://api.github.com/users/davidfstr/following{/other_user}","gists_url":"https://api.github.com/users/davidfstr/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfstr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfstr/subscriptions","organizations_url":"https://api.github.com/users/davidfstr/orgs","repos_url":"https://api.github.com/users/davidfstr/repos","events_url":"https://api.github.com/users/davidfstr/events{/privacy}","received_events_url":"https://api.github.com/users/davidfstr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-05T05:55:08Z","updated_at":"2016-09-15T05:44:34Z","closed_at":"2016-09-08T22:24:52Z","body":"This evening I decided to try out mypy on a large existing Django codebase. Hundreds of .py files.\r\n\r\nSurprisingly, I found no actual tutorial on the documentation on how to use mypy on a large existing project as opposed to single file. Therefore I will enumerate a number of issues that I have encountered so far. Perhaps such an enumeration will be useful in writing new documentation, fixing issues, or other improvements.\r\n\r\n* No documented way to run mypy on anything except single files.\r\n\r\nI tried invoking mypy on a directory rather than a single .py file. This appears to work, however the documentation does not appear to mention this usage as a possiblity.\r\n\r\n* `error: Cannot find module named 'FOO.BAR.BAZ'`\r\n\r\nI receive the following error when there certainly exists a file `./FOO/BAR/BAZ.py`. Therefore this error makes no sense to me. I invoked mypy with `MYPYPATH=. mypy .`.\r\n\r\n* `error: Need type annotation for variable`\r\n\r\nWhy? This points to a line that looks like `dependencies = []`. Error message should be improved to indicate why it is demanding a type annotation.\r\n\r\n* `error: Method must have at least one argument`\r\n\r\nWell done. This was flagging a number of unittest methods marked with `@skip` that took no arguments. Such as the following:\r\n\r\n```\r\nclass BeaconBasicTests(SimpleTestCase):\r\n    @skip('not yet automated')\r\n    def test_given_beacons_exist_when_page_reloaded_then_beacons_still_exist():\r\n        pass\r\n```\r\n\r\nIt was expecting `(self)` as the signature, which seems reasonable.\r\n\r\n* `error: Result type of + incompatible in assignment`\r\n\r\nAppears to be a mypy bug. Was complaining about the following construction:\r\n\r\n```\r\nINSTALLED_APPS = (\r\n    'django.contrib.admin',\r\n    ...\r\n)\r\nif USE_DEBUG_TOOLBAR:\r\n    INSTALLED_APPS += ('debug_toolbar',)  # error here\r\n```\r\n\r\n* `error: Value of type \"object\" is not indexable`\r\n\r\nAppears to be a mypy bug. Was complaining about the following construction:\r\n\r\n```\r\nLESSON_OBJECT_TYPES = {\r\n    'warm_up': dict(\r\n        title='Warm Up',\r\n        ...=...,\r\n    ),\r\n    ...\r\n)\r\nx = LESSON_OBJECT_TYPES['teacher_coding_exercise']['expected_file_types']  # error here\r\n```\r\n\r\n* `error: Callable[[Any, Any, Any], Any] has no attribute \"short_description\"`\r\n\r\nAppears to be a mypy bug. Was complaining about the following construction:\r\n\r\n```\r\ndef upload_deck(modeladmin, request, queryset):\r\n    ...\r\n\r\nupload_deck.short_description = 'Upload slides to selected deck'  # error here\r\n```\r\n\r\nIt is legal (albeit advanced) to annotate a function object (including a lambda) with additional attributes.\r\n\r\n* `error: Name 'Foo' already defined`\r\n\r\nCommon to receive this kind of error when using star-imports. For example:\r\n\r\n```\r\n=== A.py\r\nfrom B import *\r\nimport C\r\n\r\n=== B.py\r\nimport C\r\n```\r\n\r\nIn the above scenario mypy will complain that C is already defined in A.\r\n\r\nRecommend altering there to be an error only if Foo is defined more than once *and* is defined to be something different.\r\n\r\nThat's all folks. I suppose I'll wait to add my own type annotations until mypy gives my current unannotated code a clean bill of health."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/247240444","html_url":"https://github.com/python/mypy/issues/2096#issuecomment-247240444","issue_url":"https://api.github.com/repos/python/mypy/issues/2096","id":247240444,"user":{"login":"davidfstr","id":764688,"avatar_url":"https://avatars.githubusercontent.com/u/764688?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfstr","html_url":"https://github.com/davidfstr","followers_url":"https://api.github.com/users/davidfstr/followers","following_url":"https://api.github.com/users/davidfstr/following{/other_user}","gists_url":"https://api.github.com/users/davidfstr/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfstr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfstr/subscriptions","organizations_url":"https://api.github.com/users/davidfstr/orgs","repos_url":"https://api.github.com/users/davidfstr/repos","events_url":"https://api.github.com/users/davidfstr/events{/privacy}","received_events_url":"https://api.github.com/users/davidfstr/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T05:44:34Z","updated_at":"2016-09-15T05:44:34Z","body":"One item I forgot to mention:\r\n\r\n* Added `__init__.py` files to several packages so that they wouldn't be ignored."}}
{"actor":{"display_login":"davidfstr"}}