Friday, 23 August 2013

Mypy Development Update #3

This is a short update about what's been happening in the mypy project.

I have (mostly) been on vacation recently, and now it's time to get back to mypy development. My PhD dissertation submission deadline also looms near, so I will have to work on that as well. Actually a lot of things are happening in my life — I will be relocating after finishing with my PhD, and this will involve (the typical) things such as finding a nice neighborhood, new schools/nurseries and shipping our pets and our belongings. I have already been glacial in responding to emails recently, and things may not get better until later this year.

I've been working on several new mypy features during the summer, though some of them are still incomplete. I want to get a "good-enough" prototype mypy implementation for my dissertation, and I really don't have time to polish things at this stage, which is a bit sad but can't really be helped. After submitting I can get back to doing things in a more orderly manner.

I'm really enthusisistic about some of the new features. Here is a sketch of some of them:

  • Multiple (implementation) inheritance now mostly works. This is a side effect of the switch to Python-compatible syntax, as mypy lost the distinction between classes and interfaces.
  • Abstract methods and abstract base classes (ABCs) are supported, using the abstractmethod decorator and the ABCMeta metaclass, as in Python.
  • Static methods are supported, using the staticmethod decorator.
  • There is support for read-only properties. Support for more complex properties is not there yet.
  • Type inference of code that uses isinstance checks is getting better. The nice result is that casts are often no longer needed in cases where they used to be required.
  • Conditional expressions of form x if y else z are supported.
  • For loops over tuple literals are supported.
  • The del statement is improved. You can now delete names and attributes. These don't affect type checking yet, but it makes it easier to adapt existing code that uses del statements to static typing.
  • I'm working on support for a feature which allows a kind of string polymorphism. It lets a single function implementation to support both str and bytes arguments with effective type checking. Previously either some code duplication or using dynamically typed code was needed in cases like this. This seems like a very useful feature especially for library code. I'll get back to this later when the implementation is more complete.
  • There is now some very limited Python 2.x support. It should be straightforward but moderately laborious to finish this, but other tasks are more urgent.
  • As always, several bugs have been fixed and standard library stubs have been improved.

As I had previously planned, I'm not currently working on the compiler. I focus on getting the type system and type checker reasonably feature-complete and stable first.

3 comments:

  1. Any news on MyPy project? Too bad if it would be yet another one-man project which died after the guy had changes in personal life ;-)

    ReplyDelete
  2. Great to see progress on this project!

    I have a couple of questions:

    Since Mypy is an open source project, I'd prefer asking my questions in the public instead of by e-mail. What is the proper place for discussion (other than bug reports) about Mypy?

    You wrote on 31 Aug 2014: "Mypy no longer runs your programs, it just type checks them. Use a Python interpreter to run programs."
    Does this mean that support for run-time type checking has been dropped completely?

    I tried to use Mypy to analyze Python 2.7 code. I'm getting errors about packages which are not available for Python 3. I tried to convert the Mypy codebase using 3to2_py3k, but there were some issues for which there weren't obvious quick fixes.
    Have you considered what it would take to support analyzing Python 2.7 code which uses packages not available for Python 3? Do you see running Mypy using Python 2.7 (after converting with 3to2) as a viable "hack" to achieve this, or do you see a possible better way?

    Regards,
    Antti Kaihola

    ReplyDelete
    Replies
    1. Ok so I guess I found where most of the high-level discussion has been going on lately:

      https://mail.python.org/pipermail/python-ideas/2014-August/thread.html

      It's a lot to go through, so I'll get started...

      Delete