astroid icon indicating copy to clipboard operation
astroid copied to clipboard

Expose typing information

Open kasium opened this issue 2 years ago • 6 comments

Hi all,

if a library is using astroid and would like to check types (e.g. with mypy), the library first needs to have typing information and expose a "py.typed" file in the root package. First is partially done (AFAIK) but second not.

Can you please consider this?

kasium avatar Dec 07 '21 07:12 kasium

Hello, we already spent hundred of hours in this, as @DanielNoord can corroborate :smile: We're close to being able to activate mypy, probably not with --strict but astroid was not designed with strict typing on the radar, and there's a lot of issues that need to be resolved first. See https://github.com/PyCQA/astroid/pull/1217 or https://github.com/PyCQA/astroid/pull/1249 for example among dozen of other similar MR.

This is a prerequisite to doing the same in Pylint.

Pierre-Sassoulas avatar Dec 07 '21 08:12 Pierre-Sassoulas

Wow, great! I guess you then also expose the types by adding a py.typed file, right?

kasium avatar Dec 07 '21 08:12 kasium

Wow, great! I guess you then also expose the types by adding a py.typed file, right?

Yes, once we've enabled mypy and can be confident the types are correct.

cdce8p avatar Dec 07 '21 21:12 cdce8p

Hi guys, can you please shortly share the current status? Can you please give a hint where to contribute? Given that pylint is now typed and mypyc would be cool performance boost, I see this topic as rather important

kasium avatar Mar 08 '23 19:03 kasium

The bottleneck in pylint performance is not pylint itself but in astroid and astroid is not typed properly right now (We can't even activate mypy in non strict mode). But we exposed pylint's typing becase there's some level of separation between pylint and astroid, and most pylint API do not expose astroid's API, so it's correct enough and useful enough to be exposed.

There's another possible avenue for improvement on top of mypyc in #2014 but in all case it seems a major refactor with huge breaking changes is required to be able to type astroid correctly (https://github.com/PyCQA/astroid/issues/2014#issuecomment-1423027808) -- or do anything really.

Pierre-Sassoulas avatar Mar 08 '23 20:03 Pierre-Sassoulas

Thanks for the insights!

kasium avatar Mar 08 '23 20:03 kasium