2022/10/14 –, pyconjp_3
言語: English
We set up implicit or explicit rules in many projects. Where to create what kind of files? What's the naming convention? What's the API conventions?
Instead of keeping these rules in your head, in docs, etc. and checking them manually, what if you could write the rules as code?
With static analysis, you can automate the entire process. In this talk you'll learn how to do exactly that.
I'm sure you have seen conventions like these somewhere in your projects at work:
- All database models should use UUID as the primary key
- All widget constructors must call
super().__init__()
as the first line - All controller classes must have a name ending in
-Controller
- All API routes should start with a version prefix like
'/v1/...'
But manually verifying all of these rules is time consuming and error-prone. Oftentimes things get missed, even in code review.
Turns out, there is a much better way. It is possible to write these rules as code, and have scripts that validate your entire project before you ship it. And it's all possible due to static analysis.
With this talk, you'll learn how you can easily write scripts that enforce your project-specific conventions. Using things like Python's ast
module and pattern matching, you'll be able to ensure that the conventions are always followed, quickly and effortlessly.
22 year old software developer from India, interested in Python internals, static analysis, and type checking.