Conan: Add type annotations for mypy and jedi

Created on 19 Dec 2018  路  5Comments  路  Source: conan-io/conan

Conan currently has quite a few attributes and methods which confuse jedi, mypy and a lot of other tooling. Adding annotations to these attributes can help packagers write conanfiles more quickly and ensure they haven't forgotten anything.

It's easiest to add annotations inline with the source code (using # type: comments) however they could also be defined in a standalone file. Additionally jedi can parse rst doc comments and extract types from those.

I've put together a pull request implementing type hint comments for the basic ConanFile fields.

medium medium queue feature

All 5 comments

I think we could use type hints after to deprecate python 2 support.

Hi @barcharcraz

I would like to learn a bit better how type annotations help the users. Is that they are getting syntax highlight errors directly in their IDEs even before running conan? Would you have some captures, error messages, etc that you could share?

While I understand the use case for big codebases, and it is something that we might implement when moving to py3 only, I would like to see the value for conan users, that in general they manage just 1 file, and there are already lots of checks in the conan codebase to protect from wrong inputs.

The largest thing is getting correct completions for conanfile members. Things like scm or cpp_info.libs should show up in Jedi.

For me, it makes it much easier to remember to add all the fields I need to the conanfile. I could amend the pull request to only add required dummy variables and not mess with typing or add type hints.

Yeah, as you said, I think the important thing is to autocomplete the "complex" objects, like the cppinfo, options, settings, default_options and so on. I think we should wait for Conan 2.0 where we will use python3 and use all the power from there.

I would like to add that having type hints in the main code repository would be enormously helpful to new contributors. Trying to figure out what type a particular variable is is a game of hide-and-seek currently...

Was this page helpful?
0 / 5 - 0 ratings