[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Guido van Rossum guido at python.org
Thu Aug 4 12:20:54 EDT 2016


On Thu, Aug 4, 2016 at 4:03 AM, Daniel Moisset <dmoisset at machinalis.com> wrote:
> I'll post here another wild idea (based on the
> https://github.com/python/mypy/blob/master/mypy/build.py#L976 example), just
> thinking on instance attributes. I myself am not fully sold on it but it's
> quite different so perhaps adds a new angle to the brainstorming and has
> some nice upsides:
>
> class State:
>
>     def __instancevars__(
>         manager: BuildManager,
>         order: int,  # Order in which modules were encountered
>         id: str,  # Fully qualified module name
>         path: Optional[str],  # Path to module source
>         xpath: str,  # Path or '<string>'
>         source: Optional[str],  # Module source code
>         meta: Optional[CacheMeta],
>         data: Optional[str],
>         tree: Optional[MypyFile],
>         dependencies: List[str],
>         suppressed: List[str],  # Suppressed/missing dependencies
>         priorities: Dict[str, int]
>     ): ...

That feels too hacky for a long-term solution, and some of your
downsides are very real. The backwards compatible solution is to keep
using type comments (with initial values set to None, or `...` if
Python 2 isn't needed).

But thanks for thinking creatively about the problem!

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list