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

Bring back typing check. Meanwhile just for homeassistant/*.py #14410

Merged
merged 2 commits into from
May 12, 2018

Conversation

andrey-git
Copy link
Contributor

@andrey-git andrey-git commented May 12, 2018

Description:

Bring back typing check.

Meanwhile just for homeassistant/*.py, rest of core to follow.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

@andrey-git andrey-git requested a review from a team as a code owner May 12, 2018 09:09
@andrey-git andrey-git requested a review from balloob May 12, 2018 09:09
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Cool!

return func


def is_callback(func: Callable[..., Any]) -> bool:
"""Check if function is safe to be called in the event loop."""
return '_hass_callback' in getattr(func, '__dict__', {})
return getattr(func, '_hass_callback', False) is True
Copy link
Member

Choose a reason for hiding this comment

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

The is True shouldn't be needed. We will return a boolean anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Well, since the value could theoretically be anything, I think it's ok to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically in tests it is MagicMock

tox.ini Outdated
deps =
-r{toxinidir}/requirements_test.txt
commands =
mypy --ignore-missing-imports --follow-imports=skip homeassistant
/bin/bash -c 'mypy --ignore-missing-imports --follow-imports=skip homeassistant/*.py'
Copy link
Member

Choose a reason for hiding this comment

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

The mypy docs recommend using silent instead of skip.
http://mypy.readthedocs.io/en/latest/command_line.html#follow-imports

Copy link
Member

Choose a reason for hiding this comment

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

When I run with silent there's one additional error in bootstrap on line 301.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@balloob
Copy link
Member

balloob commented May 12, 2018

Nice!

I was talking to Instagram here at PyCon. They have released MonkeyType. It will run your test suite and then suggest types for your code.

And then FB also published Pyre, a fast type checker. We should compare performance against mypy.

@andrey-git andrey-git changed the title Bring back typing check. Meanwhile just for homeassistant/.py Bring back typing check. Meanwhile just for homeassistant/*.py May 12, 2018
@MartinHjelmare
Copy link
Member

time mypy --ignore-missing-imports --follow-imports=skip homeassistant/
...
real	0m43.617s
time mypy --ignore-missing-imports --follow-imports=silent homeassistant/
...
real	0m48.549s
time pyre --source-directory homeassistant check
...
real	0m15.407s

Pyre is designed to remember the result and state of the code and will normally only check changed code. If I run without forcing a recheck it takes less than a second to run again since nothing has changed.

time pyre --source-directory homeassistant
...
real	0m0.240s

The output is not the same as for mypy though. I get lots of these errors when running pyre:

homeassistant/util/temperature.py:23:25 Undefined name [18]: Global name `homeassistant` is undefined.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good! Core should have a look though.

What are you're plans for more typing PRs? Do you have more in pipe already?

@balloob balloob merged commit 7aec098 into home-assistant:dev May 12, 2018
@andrey-git andrey-git deleted the typing branch May 13, 2018 04:10
@balloob balloob mentioned this pull request May 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants