Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce mypy and enforce it on a few files #40

Merged
merged 2 commits into from
Jun 17, 2018
Merged

Introduce mypy and enforce it on a few files #40

merged 2 commits into from
Jun 17, 2018

Conversation

asottile
Copy link
Contributor

@asottile asottile commented Jun 16, 2018

to be honest, I'm not exactly sure how I got here -- I was reading through the project to try and understand what it does and noticed #15 and somehow my first thought was "oh hey, that sounds like fun". I applied it to a few modules and then got to a point where I needed to actually understand the code to make further progress and so I decided to commit what I had and make a PR.

This also (selfishly?) adds pre-commit as an easier way to run linting (I noticed there wasn't currently any automated linting in CI so I added it! EDIT: had to change from pep8 -> flake8 so that type annotations weren't false positives) -- this part isn't entirely necessary as mypy can be invoked directly.

Copy link
Contributor

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for starting this!

  • Lets just tidy up the imports to be:
    from typing import a, b, c
  • Please use () to span multiple lines if you need to

I do plan to black code style bandersnatch soon.

from typing import Any
from typing import Dict
from typing import Optional
from typing import Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not all one from?
i.e.
from typing import (Any, Dict, Optional, Type)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal preference though if you'd like a different style I will change it.

I use reorder_python_imports -- the style here aims to reduce merge conflicts above everything else.

If you'd like, I could set you up with isort in this PR as well, that way we don't have to bicker about needless style

@@ -89,7 +94,7 @@ def update_safe(filename, **kw):
prefix=os.path.basename(filename) + '.', **kw) as tf:
if os.path.exists(filename):
os.chmod(tf.name, os.stat(filename).st_mode & 0o7777)
tf.has_changed = False
tf.has_changed = False # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the error here? I feel we should be able to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_changed is not an attribute of file objects, there's attribute stuffing happening here

@@ -1,7 +1,4 @@
flake8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we still use flake8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but via pre-commit. pre-commit manages the installation in a separate environment so you don't have to worry about system installation of tools

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only like people to have the ability to run things manually.

  • Sorry about all the questions, I am a GitHub noob, been locked away in Facebook for to long.

I'm not quite Dave Harrington n00b, but close.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hey there @DaveHarrington -- small world I guess?

@cooperlees
Copy link
Contributor

All sounds good - If you're down to add isort too that would be awesome. Then I'll follow up with a black style pre-commit + PR so style is behind us :)

Copy link
Contributor

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hot. This is awesome. Thanks!

pre-commit run --all-files --show-diff-on-failure

[isort]
include_trailing_comma = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this if black does not agree here. I can't remember.

@cooperlees
Copy link
Contributor

I'll also plan to use MonkeyType or like tool to get more type annotations for free.

@cooperlees cooperlees merged commit 2722513 into pypa:master Jun 17, 2018
@asottile asottile deleted the some_mypy branch June 17, 2018 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants