Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Use mypy and types in the code base #23

Open
punchagan opened this issue Sep 12, 2019 · 7 comments
Open

Use mypy and types in the code base #23

punchagan opened this issue Sep 12, 2019 · 7 comments
Assignees

Comments

@punchagan
Copy link
Member

No description provided.

@punchagan
Copy link
Member Author

Here's a blog post by Zulip on how to add type annotations to an existing code-base.

@punchagan
Copy link
Member Author

mypy also has some documentation for this, to help get started.

@vkrishnaswam vkrishnaswam self-assigned this Sep 16, 2019
@vkrishnaswam
Copy link
Collaborator

Got mypy running, will update requirements.txt to include mypy.
Output of current mypy run below, without a config file, will work on fixing them next.

sotg_accreditation_tracker/settings.py:105: error: Cannot find module named 'dj_database_url'
sotg_accreditation_tracker/settings.py:105: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
tracker/models.py:10: error: Need type annotation for 'name'
tracker/models.py:11: error: Need type annotation for 'email'
tracker/models.py:12: error: Need type annotation for 'type'
tracker/models.py:15: error: Need type annotation for 'date'
tracker/models.py:24: error: Need type annotation for 'uc_username'
tracker/models.py:30: error: Need type annotation for 'wfdf_userid'
tracker/models.py:37: error: Need type annotation for 'last_modified_at'
tracker/migrations/0001_initial.py:10: error: Need type annotation for 'dependencies' (hint: "dependencies: List[<type>] = ...")
uc_api_helpers.py:10: error: Cannot find module named 'faker'
uc_api_helpers.py:15: error: Need type annotation for 'HEADERS' (hint: "HEADERS: Dict[<type>, <type>] = ...")
tracker/forms.py:1: error: Cannot find module named 'crispy_forms.helper'
tracker/forms.py:2: error: Cannot find module named 'crispy_forms.layout'
tracker/views.py:5: error: No library stub file for module 'arrow'
tracker/views.py:5: note: (Stub files are from https://github.com/python/typeshed)

@punchagan
Copy link
Member Author

Got mypy running, will update requirements.txt to include mypy.

May be we should add a requirements-dev.txt where we add mypy, since we don't want it installed in Heroku? But then doing a pip freeze won't work unless we have a separate dev environment for developers, I guess. Need to figure out if there's a better workflow for doing this!

@punchagan
Copy link
Member Author

https://pypi.org/project/pip-tools/ may be good tooling to do this kind of a thing. But, this could be done later, too, I suppose. (As a separate issue, and not a part of this).

@Adityar93
Copy link

Adityar93 commented Sep 17, 2019 via email

@punchagan
Copy link
Member Author

Not really. The Zulip code base uses typed Python and has been one of the first medium-large projects to adopt mypy. It's been quite useful for the project both in terms of helping with catching bugs early and making it easier to grok the code for new contributors.

https://blog.zulip.org/2016/10/13/static-types-in-python-oh-mypy/

Also, some of the folks here also would like to contribute to Zulip - and learning some of the tooling in a smaller project might help. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants