Interview: Koudai Aono, Author of pydantic Plugin for PyCharm

I’ve long been a big fan of pydantic by the prolific Samuel Colvin. In 2018, the package added support for dataclasses by providing its own decorator which “creates (almost) vanilla python dataclasses with input data parsing and validation.”

Alas, the “almost” was a sticking point. In particular, PyCharm’s code insight only treated the built-in decorator as something providing dataclass support. A PyCharm plugin was needed, first to make PyCharm treat pydantic dataclasses like regular ones, then to fill in coding assistance for the other aspects.

Enter Koudai Aono. Despite never having done an IntelliJ plugin, nor even much Java, he took on the task of making the Pydantic PyCharm Plugin. While we helped a bit, Koudai has generated over 20 releases and updates and is now working on really impressive features.

koudai_aono

We asked Koudai to do an interview with us about pydantic, his plugin, and the experience of writing a plugin.

Thanks for joining us. Can you give some background on yourself?

I’ve been living in Japan ever since I was born 32 years ago. I work as a software engineer for FULL MARKS, Inc, which is in Tokyo.

I started my programming career in computer science at a university. I chose Python to create software. Of course, I write other languages like TypeScript, JavaScript, Bash, Java, Go, by a situation.

How did you get involved with Python?

For personal projects and for work, I have developed many apps in Python.

I chose Python because I can use it in many use cases, which are small scripts, web apps, CLI/GUI apps, and cross-platform apps. Also, Python has an excellent community and a lot of third-party libraries.

Furthermore, I develop OSS software in Python. And I contribute to some projects to support the community.

Can you explain what is interesting about pydantic and how you got involved with it?

Python is a popular programming language that is dynamically typed. This feature provides us a few benefits, which include improving development speed.

However, we often must check the type of data and validate data. Pydantic has dataclasses with the same interface as Python’s dataclasses. But Pydantic’s dataclasses validate data and cast values to a defined type based on type annotations.

Pydantic has changed my coding style in Python, which increases the quality and my development speed.

Additionally, pydantic is used in FastAPI, which is a web framework made by Sebastián Ramírez. It’s recently popular in the Python world.

What prompted you to write a PyCharm plugin for pydantic?

I used pydantic in a few projects. Moreover, I contributed pydantic via GitHub.

One time, we found a situation that PyCharm could not analyze the signatures of __init__ method. The issue complicated my development. PyCharm could not inspect callable expression correctly when we instantiated pydantic’s dataclass. For example, when you instantiate a class in Python, you expect PyCharm to suggest signatures by autocomplete. Also, you would expect PyCharm to check the signature names and types.

We had known we could not resolve by changing pydantic’s code. But we could change the PyCharm implementation or create a PyCharm plugin.

You mentioned you haven’t done much Java and certainly haven’t written an IntelliJ plugin. Was it hard to get started?

We have to write Java or Kotlin to create a plugin.

I selected Kotlin to write a plugin because I am not a Java expert. Kotlin is a modern language which, if you have experience of other modern languages like Swift or TypeScript, then you can write Kotlin easily.

And, Intellij supported me when I wrote a plugin in Kotlin. I could write a plugin without stress.

How many releases before the plugin was useful for others?

It took a while. I needed to learn how to implement a feature in a plugin. PyCharm provides excellent APIs for developers.

I started with a small codebase to implement the minimum required functionality.

You have passed “basic support” and have now implemented refactorings, configurable warning levels, and more. What feature do you find is most useful when using the plugin?

I recommend __init__ signature inspection and auto-completion for pydantic models.

Notably, auto-completion is very powerful. The popup shows the signature type and remaining signatures. It means we don’t need to watch the model definition to confirm field names and field types. It can improve your coding speed and reduce stress.

What are some things JetBrains and PyCharm could do to produce more plugin success stories such as yours?

We need more examples and documentation of learning about writing plugins.

I read the official documentation for a plugin. It is a good start to develop a new plugin. However, the document doesn’t include features of PyCharm like Python’s AST. I had to check the PyCharm source code to understand it.

I hope in the future to read more examples and API references for PyCharm. Plus, the webinar with Joachim Ansorg is an excellent resource.

What has the experience been like to run an open-source project?

It’s an excellent experience.

Pydantic’s community members have supported me. They include pydantic’s author Samuel Colvin and pydantic’s collaborator David Montague. Also, I created an issue in JetBrains’ issue tracker.

I discussed it with PyCharm core developer Semyon Proshev on this issue page. He implemented a feature in PyCharm to resolve our need for a plug point. And the feature has been released as PyCharm 2020.1.

I appreciate all the support I received from everyone.

Have any big ideas for future releases?

Yes, I have some ideas. For example, I am developing a code generator which is called datamodel-code-generator for pydantic models from OpenAPI, JsonSchema, JSON data, and other data. I plan to run this code generator on PyCharm by clicking the context menu of a file like OpenAPI.

Moreover, I hope to create another plugin which improves auto-completion and type-checking inspection by type annotation. I have gained some knowledge of PyCharm in the current project which will be useful in the next one.

This entry was posted in Interview and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *