KOPYA NG SALIN 🔗
WEBVTT
NOTE
Transcription provided by Podhome.fm
Created: 7/6/2024 5:38:33 PM
Duration: 3105.089
Channels: 1
1
00:00:13.344 --> 00:00:24.640
Hello, and welcome to Podcast Thought in It, the podcast about Python and the people who make it great. When you're ready to launch your next app or want to try a project you hear about on the show, you'll need somewhere to deploy it. So check out our friends over at Linode.
2
00:00:25.235 --> 00:00:32.535
With their managed Kubernetes platform, it's easy to get started with the next generation of deployment and scaling powered by the battle tested Linode platform,
3
00:00:33.020 --> 00:00:39.040
including simple pricing, node balancers, 40 gigabit networking, and dedicated CPU and GPU instances.
4
00:00:39.740 --> 00:00:47.295
And now you can launch a managed MySQL, Postgres, or Mongo database cluster in minutes to keep your critical data safe with automated backups and failover.
5
00:00:47.675 --> 00:00:49.370
Go to python podcast dotcom/linode
6
00:00:50.230 --> 00:01:22.840
today to get a $100 credit to try out their new database service. And don't forget to thank them for their continued support of this show. The biggest challenge with modern data systems is understanding what data you have, where it is located, and who is using it. Select STAR's data discovery platform solves that out of the box with a fully automated catalog that includes lineage from where the data originated all the way to which dashboards star will set everything up in just a few hours. Go to Python podcast star will set everything up in just a few hours.
7
00:01:23.300 --> 00:01:24.520
Go to python podcast.com/selectstar
8
00:01:26.180 --> 00:01:30.485
today to double the length of your free trial and get a swag package when you convert to a paid
9
00:01:30.965 --> 00:01:43.470
plan. Your host as usual is Tobias Macy. And today, I'm interviewing Shannon Zhu about pyre, a type checker for Python 3 built from the ground up to support gradual typing and deliver responsive incremental checks. So, Shannon, can you start by introducing yourself?
10
00:01:43.850 --> 00:01:54.585
Yeah. Hi. My name is Shannon. I'm a software engineer at Meta, and I've been working on Pyre team building a type checker and static analyzer for Python for the last 5 or so years.
11
00:01:54.900 --> 00:01:57.159
And do you remember how you first got introduced to Python?
12
00:01:57.619 --> 00:02:02.680
Yeah. So my very first programming languages, I believe, were Java and C.
13
00:02:03.145 --> 00:02:08.364
And I think my initial deeper exposure to Python was when I started using it to prep for
14
00:02:08.825 --> 00:02:10.525
my very first coding interviews.
15
00:02:10.840 --> 00:02:17.420
That was the first opportunity that I really started to get familiar with the language, and I think I kind of quickly realized that some of the same,
16
00:02:17.875 --> 00:02:23.415
like, properties that make it such a good choice for technical interviews also makes it a really good learning language too.
17
00:02:23.715 --> 00:02:25.655
So, yeah, that was probably my first exposure.
18
00:02:26.180 --> 00:02:35.640
Can you describe a bit about what the Pyre project is and some of the story behind either how it got started, if you are familiar with that history or at least your
19
00:02:36.165 --> 00:02:41.065
introduction to it and why you wanted to spend your time and energy on this particular area.
20
00:02:41.445 --> 00:02:44.345
The first part, you know, is like, what is Pyre? It's, I guess, simply
21
00:02:44.920 --> 00:02:49.580
type checker for Python, and we originally started building this back in
22
00:02:50.120 --> 00:02:50.620
2017.
23
00:02:51.560 --> 00:02:55.495
And some of the initial motivation there was to solve the
24
00:02:55.795 --> 00:02:56.534
type checking
25
00:02:56.915 --> 00:03:03.000
needs for Instagram, which is a huge Python code base. And they were 1 of the very first early adopters
26
00:03:03.459 --> 00:03:07.879
for Python annotations when they were kind of introduced to the language in PEP 484.
27
00:03:08.739 --> 00:03:14.565
And the codebase is growing really fast, and we really needed faster type checking
28
00:03:14.945 --> 00:03:18.005
results to keep that development experience reasonable.
29
00:03:18.305 --> 00:03:21.205
So that was 1 big motivation. Another thing was that
30
00:03:21.570 --> 00:03:22.790
Meta actually has
31
00:03:23.170 --> 00:03:23.830
a somewhat,
32
00:03:24.210 --> 00:03:34.025
like, long standing track record for adding types to dynamic languages and then building static analysis tools for security on top of it. So some examples prior to pyre would
33
00:03:34.325 --> 00:03:37.065
be flow for JavaScript and hack for PHP.
34
00:03:37.365 --> 00:03:38.825
And so there was some,
35
00:03:39.150 --> 00:03:51.805
you know, intention to do the same thing for Python since those have been so successful in the past. So I thought it was a really exciting space. I like Python from what I had used it for in the past, and I thought it was a really interesting problem to kind of build,
36
00:03:52.905 --> 00:04:00.090
type checker for such a dynamic language. I joined the team around when it was started, so that's kind of the story for for the team.
37
00:04:00.470 --> 00:04:01.530
In terms of
38
00:04:01.990 --> 00:04:18.690
type checking, particularly with Pyre, but also with some of the other suite of tools that are out there, what are some of the ways that that capability fits into the development workflow as you're working on a particular code base, either starting from scratch or jumping into a massive code base such as Instagram?
39
00:04:19.310 --> 00:04:52.310
Yeah. So the most common use case probably is for a developer who's already working on a project that has type checking turned on, and they'll interact with the type checker via either the command line or more commonly their editor when they just open a Python file. We spin up a type
Load full transcript
checking server quietly by default in the background, and they'll just get type errors as they write code. And then they'll probably see it again in continuous integration. So when they submit their changes for review, we usually provide signal both, you know, whether this change introduced type issues in your project or maybe in a downstream dependency.
40
00:04:52.690 --> 00:05:04.315
But there are also maybe additional lints or, like, coverage delta signal that you might get in the CI as well. So that's kind of the most common, I think, use case. But definitely for teams
41
00:05:04.759 --> 00:05:07.660
who are interested in, like, just starting out with types or
42
00:05:08.039 --> 00:05:11.419
or maybe taking their, like, really driving type annotations,
43
00:05:11.995 --> 00:05:28.900
We also have, like, different interfaces and tools for them to sort of, like, push some buttons and either turn on type checking, make it more strict, or do code mods for type coverage, things like that. So I suppose that's 1 other dimension where you might interact with Pyre that's not just,
44
00:05:29.805 --> 00:05:32.545
showing type errors in your editor or in your CI.
45
00:05:33.005 --> 00:05:53.885
In Python, there have been a number of other tools that have come about for being able to interact with types and specifically for type checking where maybe the canonical example is mypy because of the fact that Guido was 1 of the people who was involved in its early development efforts. And I'm wondering if you can describe some of the
46
00:05:54.300 --> 00:05:55.440
landscape and ecosystem
47
00:05:55.980 --> 00:05:59.360
of type inference and type validation and type annotations,
48
00:06:00.220 --> 00:06:07.585
particularly as it pertains to these type checkers and some of the different goals and focus that those different tools adhere to?
49
00:06:08.205 --> 00:06:13.780
Yeah. So MyPy is a great example. There is also HiType at Google and Pyrate at Microsoft.
50
00:06:14.400 --> 00:06:16.099
So I think these 4 are
51
00:06:16.400 --> 00:06:19.940
typically the biggest names in the type checking space for Python.
52
00:06:20.479 --> 00:06:21.940
I guess Pyre in particular
53
00:06:22.615 --> 00:06:25.194
definitely started out with the goal of just being,
54
00:06:25.574 --> 00:06:38.400
like, blazingly fast on huge code bases, you know, Instagram being our, like, urgent need. And it's written in OCaml, which I think is pretty different from a lot of the implementations of other type checkers, which are usually themselves written in Python.
55
00:06:38.745 --> 00:06:54.850
And so a big focus for us was to get, like, sub second response times for changes in the editor that are also, you know, absolutely guaranteed to always be consistent with a full cold type check. So we did a lot of work on performance and consistency reliability, basically,
56
00:06:55.155 --> 00:06:59.255
on really large code bases. So that was that was definitely, like, our number 1
57
00:06:59.555 --> 00:07:16.825
number 1 goal and a big reason that we didn't just go with MyPy, for example, internally, which is what Instagram started on. And I think some other differences, you know, Pyre also tends to be a relatively more opinionated type checker in the space. So, we only really support 2 modes. There's gradual typing and there's strict typing.
58
00:07:17.205 --> 00:07:32.215
And within each of these modes, Pyre takes a pretty strong stance on what is type safe and what is not, and it doesn't really allow users to, like, fiddle with tons of flags and opt ins and optionality for, like, you know, enabling or disabling different pieces of the type system or, like, different interpretations
59
00:07:32.515 --> 00:07:34.215
of Python type system,
60
00:07:34.860 --> 00:07:42.880
which maybe is either a good or bad thing, but the type system itself is pretty specified as, like, kind of a skeleton, like, their syntax and their operators.
61
00:07:43.245 --> 00:07:45.905
There's some rules, but there isn't a lot of, like, concrete
62
00:07:46.765 --> 00:07:48.465
specification on the expected
63
00:07:48.765 --> 00:07:52.360
type output, like, type error output or behavior of every particular pattern.
64
00:07:52.740 --> 00:08:21.475
So that is 1 way that different type checkers might might be different. Like, they actually may output slightly different errors in different places, things like that. And I think the last thing that might be, you know, interesting to call out is is, again, the static analysis for security application. So that has been a focus for the Pyre team in the past, and it's even bled into some PEPs. Like, if you're curious to, like, you know, hear more about security applications for types, We recently published, and it's included in 311 with
65
00:08:22.414 --> 00:08:31.270
675, which is arbitrary literal string. So that's another thing that at least our team really focuses on as, like, 1 application of type checking that I don't think is really
66
00:08:31.730 --> 00:08:34.070
as much in the forefront of some of the other
67
00:08:34.450 --> 00:08:35.670
tools in the ecosystem.
68
00:08:36.334 --> 00:08:39.875
The fact that it's implemented in OCaml is an interesting
69
00:08:40.334 --> 00:08:45.315
juxtaposition where OCaml is a very strongly typed language and functional,
70
00:08:45.820 --> 00:08:48.959
and you're working on a dynamically typed language
71
00:08:49.339 --> 00:08:50.080
that is,
72
00:08:50.620 --> 00:08:52.880
I guess, agnostic to paradigm. And so
73
00:08:53.445 --> 00:08:59.865
working in OCaml to do type checking in Python, I'm curious what you have seen as some of the interesting kind of juxtapositions
74
00:09:00.245 --> 00:09:03.620
or lessons learned as you jump between the 2 different environments.
75
00:09:04.240 --> 00:09:10.645
Yeah. That is really interesting to call out. They're just worlds apart. You know, OCaml is kind of the language where you're fighting with
the compiler
76
00:09:11.025 --> 00:09:14.005
to the death, but, like, once it compiles, it, like, definitely works,
77
00:09:14.625 --> 00:09:17.125
or, like, more or less definitely works. And so
78
00:09:17.425 --> 00:09:18.005
I think
79
00:09:18.420 --> 00:09:19.800
it hasn't felt so
80
00:09:20.339 --> 00:09:25.080
strange, honestly. Like, it doesn't feel too weird to be working in OCaml for Python,
81
00:09:25.460 --> 00:09:31.125
but it definitely does, you know, help us have a concrete appreciation for what a very sound
82
00:09:31.504 --> 00:09:45.160
type system or a very complete type system can give you. The level of just safety guarantee. Like, you can just do refactors and make changes with just such an insane level of confidence that it'll tell me if I forgot something, if I wasn't aware of some dependency,
83
00:09:45.605 --> 00:09:48.745
and it's something you're pretty used to not having in Python.
84
00:09:49.125 --> 00:09:56.320
So I guess in some ways, it does provide that kind of tangible illustration of what a really sound type system can do. I'm wondering,
85
00:09:56.779 --> 00:10:07.465
as you go from working in OCaml to working in Python, if there are any ways that that influences the way that you approach development of your Python code to be maybe more
86
00:10:07.845 --> 00:10:19.840
strict or detailed with the it type annotations that you're adding to try and get back some of that level of confidence and just some of your, some some of the perspective that it provides you working between those language environments?
87
00:10:20.565 --> 00:10:23.065
I actually say not really. I think we really
88
00:10:23.685 --> 00:10:28.190
keep in mind the value of, like, the simplicity and cleanliness of Python.
89
00:10:28.730 --> 00:10:34.270
And, you know, the goal isn't really to build a totally sound type system and
90
00:10:34.865 --> 00:10:40.084
capture all of the dynamic possibilities of the language and express them in the type system. Although, you
91
00:10:40.464 --> 00:10:45.270
may be surprised by, like, just how expressive the type system can be on things that are quite dynamic.
92
00:10:45.650 --> 00:10:47.190
But I don't think working in OCaml
93
00:10:47.570 --> 00:10:51.910
brings us to the Python type checking space with, like, more of an eye for, like,
94
00:10:52.445 --> 00:11:01.505
really sound complex types. Like, I think the languages are different enough that we we definitely viewed the type system in Python as, like, a completely different beast.
95
00:11:01.850 --> 00:11:16.005
It was tacked on afterwards on, like, a pretty fully fledged language, and that's pretty neat. So, yeah, I I don't think it it necessarily applies in a very concrete sense, but it perhaps, like, gives us, yeah, that appreciation for, you know, if we had,
96
00:11:16.465 --> 00:11:24.470
like, very well typed code, like, what could the development and iteration process look like, and how fast could it be, if that makes sense.
97
00:11:25.785 --> 00:11:41.960
Another interesting element of to your point, the type system well, I guess the type system was already there, but the type annotations and type enforcement in Python is something that was added as not necessarily an afterthought, but added as something that to to an already existing language and ecosystem,
98
00:11:42.655 --> 00:12:00.915
which brings up the idea of gradual typing, which is 1 of the goals of Pyre. And I'm wondering if you can talk to some of the ways that that manifests. And for people who might not be familiar with that concept, sort of what that actually means to be able to do gradual typing and how you might incorporate that into an existing code base?
99
00:12:01.535 --> 00:12:05.475
Basically, gradual typing is a necessary crutch in order to
100
00:12:05.959 --> 00:12:09.980
convert an existing Python project that doesn't have types into
101
00:12:10.360 --> 00:12:15.019
1 that does without saying halting all production and getting
102
00:12:15.515 --> 00:12:17.375
your entire team to just
103
00:12:17.755 --> 00:12:22.975
annotate things for a few months, which is just never realistic in the real world. So gradual typing
104
00:12:23.460 --> 00:12:24.920
essentially is a way to,
105
00:12:25.700 --> 00:12:28.520
like, add a stopgap. Like there's basically
106
00:12:29.300 --> 00:12:37.584
a type that we use that kind of breaks the type system. It can be compatible with any other type, and this is used in gradual typing to
107
00:12:37.885 --> 00:12:41.264
allow you to incrementally add types and only deal with
108
00:12:41.620 --> 00:12:42.440
type inconsistencies
109
00:12:42.980 --> 00:13:10.085
between the types you've already added rather than having to deal with all the downstream effects of every type that you've added, which essentially becomes 1 of those viral problems where you end up with more and more and more errors and fixing those results in more errors until you find yourself sitting down to convert your entire code base in 1 sitting, which is not possible. So, yeah, gradual typing is basically a mode where, you know, you can add types as you go, and the type checker just makes blanket assumptions about everything that doesn't have a type and assumes it's compatible.
110
00:13:10.545 --> 00:13:40.570
This trades off obviously with soundness and safety guarantees. If you have a gradually typed project, you might not know exactly how much of it is covered. You You might not know how much your of your dependencies are covered, and so you don't know how much to trust the type checker when it says, like, you're all good. There's no type errors. So it definitely is like a a phase that we try to move projects through and and out of eventually into stricter type checking to gather more of those guarantees. But it's totally necessary for a language and a type system like this where types are being added
111
00:13:40.950 --> 00:13:42.890
to existing things in most cases.
112
00:13:43.455 --> 00:13:45.315
Is there any real distinction
113
00:13:45.695 --> 00:14:07.945
from that kind of gradual typing mode and the type inference that a type checker might do where you say, I have a variable foo and I initialize it to an integer 1. And so I'm going to assume that for the lifetime of this project that foo is has a type of int? And then if I see that you assign a string to foo, then I'm going to throw an error. Like, is it the the similar
114
00:14:08.360 --> 00:14:11.900
approach to that, or is it a kind of different layer above that?
115
00:14:12.280 --> 00:14:13.820
Oh, yeah. So I would actually
116
00:14:14.280 --> 00:14:16.380
separate those 2 concepts. I think
117
00:14:16.760 --> 00:14:17.660
gradual typing,
118
00:14:18.105 --> 00:14:20.445
at least when we talk about it on pyre,
119
00:14:20.825 --> 00:14:33.790
I think mostly in the typing community, it refers to the adoption process for types. Whereas type inference is definitely a a critical part and baked into every type checker and maybe more manifest in the idea that not everything
120
00:14:34.410 --> 00:14:39.795
in the Python program needs types. So conventionally, we only ask for explicit annotations
121
00:14:40.495 --> 00:14:46.595
on really globally accessible values. So that might be the globals, class attributes, and function signatures.
122
00:14:46.960 --> 00:14:49.380
And then everything else, a lot of local values, etcetera,
123
00:14:50.000 --> 00:14:51.140
are all inferable
124
00:14:51.520 --> 00:14:54.100
from that set of globally accessible values.
125
00:14:54.400 --> 00:14:55.220
And, therefore,
126
00:14:55.944 --> 00:15:05.404
Python doesn't wind up looking like a language where every single variable initialization needs an explicit type. In terms of being able to actually go from a project that
127
00:15:05.920 --> 00:15:15.220
is functioning, you're using it, it's running in production, and then you say, okay. I wanna start adding type information into this program because I'm starting to hit some of these roadblocks where
128
00:15:15.825 --> 00:15:27.310
I change a value or I change the type of a variable, and then all of a sudden my code starts breaking. So I just wanna understand what is this value even supposed to be? Because I'm 5 layers deep in the stack, and I don't know where it originated.
129
00:15:27.690 --> 00:15:43.660
And so I know that there are projects such as monkey type that are aimed at looking at the runtime behavior of your program and then generating the type stubs so that you can layer those in afterwards. And I'm wondering, you know, over and above that, if there are any other kind of useful strategies that you've seen teams take for being able to
130
00:15:44.120 --> 00:15:55.574
start figuring out what are the right types to add and what are the right places to think about adding those types so that I can get some of those kind of safety checks and kind of guardrails in the project.
131
00:15:56.000 -->
00:15:58.660
Yeah. So monkeytype is a great example of 1
132
00:15:59.040 --> 00:16:05.620
way to automate adding annotations at scale. So it's really neat because it's dynamic and it it samples from your
133
00:16:05.995 --> 00:16:12.720
actual run time traffic and figures out what types might be. Then there's the static inference as well, which essentially just
134
00:16:13.360 --> 00:16:19.939
reuses the same engine that powers inference in the type checker itself to propagate whatever types it can infer
135
00:16:20.445 --> 00:16:28.625
and add explicit annotations, like, guess at explicit annotations. So those are definitely 2 ways to just automate the process entirely, but not everything
136
00:16:29.220 --> 00:16:38.200
can necessarily be automated. And automation tools also do benefit from, like, a seeding of, like, manually added types in many cases. Right? Like, some partial
137
00:16:38.705 --> 00:16:47.445
percentage of type annotations often makes at least a static inference a lot more powerful. So other approaches that I've seen teams take with
138
00:16:47.839 --> 00:16:50.339
quite a lot of success usually revolve around
139
00:16:50.880 --> 00:17:08.490
measuring coverage and making it very visible to developers. So a couple different forms, like either as the project as a whole and setting kind of better engineering goals and measuring individual contributions to type coverage. For example, changes that get submitted can very easily be dealt against
140
00:17:08.790 --> 00:17:11.930
coverage stats on the base and figure out, you know, like, who's
141
00:17:12.470 --> 00:17:16.365
making the effort to annotate more code, annotate new code or existing code, etcetera.
142
00:17:16.905 --> 00:17:23.645
Another thing that we've recently been pushing for is something we call expression level type coverage, which
143
00:17:24.020 --> 00:17:25.160
basically exposes
144
00:17:25.540 --> 00:17:26.680
holes in the
145
00:17:27.300 --> 00:17:28.200
type inference
146
00:17:28.900 --> 00:17:31.480
process. So, I mean, basically, every
147
00:17:31.795 --> 00:17:35.815
type coverage hole will usually come from some missing annotation somewhere upstream.
148
00:17:36.275 --> 00:17:38.215
But, you know, like, I might be
149
00:17:38.675 --> 00:18:09.304
somewhere in in the body of some function where my function is perfectly typed and my entire module is perfectly typed. And maybe my whole project is strictly typed, and we have 99% type coverage. But then I might be shocked to find that I run this code and I get type errors that weren't caught by the type checker. And oftentimes, that's because I'm calling some function that's in the dependency and that project is poorly typed. So being able to expose to the user in, like, a visual way what the type inference engine thinks it's confused about
150
00:18:09.605 --> 00:18:11.945
is also another interesting way to both
151
00:18:12.245 --> 00:18:12.745
motivate
152
00:18:13.125 --> 00:18:14.265
more type coverage
153
00:18:14.645 --> 00:18:20.330
and maybe even identify, like, the libraries that are causing the most coverage holes downstream and,
154
00:18:20.870 --> 00:18:22.330
you know, push people to
155
00:18:22.665 --> 00:18:31.325
annotate those. And also avoid surprising people when, you know, they have a well typed module. And, for some reason, the type checker is still blind to some pieces.
156
00:18:31.649 --> 00:18:36.309
That helps with the level of safety guarantee even if they can know, like, where the blind spots are.
157
00:18:36.929 --> 00:18:43.955
Question of coverage is also interesting because it's definitely possible to have everything in your code base with a type annotation
158
00:18:44.655 --> 00:18:48.195
and still not get any of the safety guarantees because everything is just in any type.
159
00:18:48.815 --> 00:18:52.950
And I'm wondering if there's any utility or capacity for being able to
160
00:18:53.490 --> 00:18:53.990
visualize
161
00:18:54.850 --> 00:19:00.674
not just the coverage, but the specificity of the types and whether or not it is actually covering the kind
162
00:19:00.975 --> 00:19:04.835
of right level of constraint where you say, okay. You have 95%
163
00:19:05.135 --> 00:19:11.610
type coverage, but 30% of your dictionaries are just type string any, so maybe you need to be a little bit more specific about that.
164
00:19:12.150 --> 00:19:17.210
Yeah. So for the purposes of coverage statistics, any counts as not types.
165
00:19:17.545 --> 00:19:35.805
But you're totally right. They can be embedded in other types. And so oftentimes, coverage gets a little bit more complicated where we have the concept of, like, a partially typed value where you might have, like, a list of any. So you know something about it, but you don't know everything, and you'll still get unknowns when you pull out of this list. Or, yeah, like the common dict string any
166
00:19:36.105 --> 00:19:37.485
oftentimes used for JSON.
167
00:19:37.945 --> 00:19:52.225
So, there is a little bit more nuance too in flagging not just, like, black and white, what is covered and what isn't, but also what's partially covered. As far as I'm aware, I think some other type checkers also have a, like, similar concept of, like, what is uncovered
168
00:19:52.845 --> 00:20:00.610
but is inferable. So, like, the type checker is making an educated guess, but it would be better if you annotated it, something like that. So there are different
169
00:20:00.990 --> 00:20:05.170
nuances to measuring coverage and showing it to developers in a useful way.
170
00:20:05.495 --> 00:20:16.920
Digging more into the Pyre project itself, you already mentioned that it's written in OCaml. I'm wondering if you can talk through some of the implementation and design and some of the ways that you think about the architecture
171
00:20:17.300 --> 00:20:21.320
of a type checker as compared to maybe like a web application.
172
00:20:22.105 --> 00:20:27.005
Sure. Yeah. I can do sort of a high level overview of how the type checking is put together.
173
00:20:27.465 --> 00:20:38.750
So, essentially, Pyre does have a, like, a Python client which handles, you know, the command line interface, file system changes, and code editor integrations, but the core type checking is all done in OCaml.
174
00:20:39.155 --> 00:20:44.695
We spin up a server, basically, that can be pinged for by the client for any incremental changes.
175
00:20:45.075 --> 00:20:58.655
And the server itself, when you type check something for the very first time, it will parse your Python source code and build an abstract syntax tree. And then it does some pre processing on this tree to deal with like name qualification,
176
00:20:59.674 --> 00:21:09.110
handle versioning, you know, expand some syntactic sugar and all that kind of stuff. So that's kind of the first step. And then we enter a phase that we call environment building.
177
00:21:09.595 --> 00:21:11.615
So for pyre, we basically
178
00:21:12.075 --> 00:21:14.335
have a bunch of parallelizable layers
179
00:21:14.875 --> 00:21:18.735
and each layer collects some kind of global information that
180
00:21:19.180 --> 00:21:24.160
subsequent layers depend on. So, you know, we'll be collecting things like class names, function signatures,
181
00:21:24.620 --> 00:21:25.360
type aliases,
182
00:21:25.660 --> 00:21:27.985
like global values, and then eventually we'll,
183
00:21:28.304 --> 00:21:38.490
after being able to gather all of this information, we can build out, like, a class hierarchy and an ordering of types. So all of these are essential to answer questions about,
184
00:21:38.790 --> 00:21:48.945
you know, whether some type is less than or equal to some other type and to know, like, if I make a function call, what's the type like, basically, be able to resolve the types of anything that's globally visible.
185
00:21:49.485 --> 00:21:50.625
And then the
186
00:21:50.980 --> 00:21:55.720
final step really is the type checking itself. And so we type check all local scopes
187
00:21:56.020 --> 00:21:57.240
of code in parallel.
188
00:21:57.620 --> 00:22:01.565
Once we have that global information, all of the local scopes are independent.
189
00:22:02.185 --> 00:22:27.335
I guess, nesting is maybe an asterisk, but, essentially, we have the AST, and we turn that into a control flow graph. You know, branches on if else statements, but generally just steps through, like, the execution path of the code. We analyze that statement and apply changes to, like, a set of inferred local types. We do this on a fixed point, and so we eventually have a snapshot of what the local type environment is at every statement, and then we can generate errors.
190
00:22:27.700 --> 00:22:37.160
And in the final exit statement of the local scope, we have a final set of errors at the end. We do a little bit of post processing, and that's what we show the users.
191
00:22:37.645 --> 00:22:40.065
Let me know if I can get into any more detail, or
192
00:22:40.365 --> 00:22:43.425
that's, like, the high level bird's eye view of of how Pyre is implemented.
193
00:22:43.805 --> 00:22:56.955
Yeah. And 1 thing I'm interested in digging a little deeper into is kind of the state management where when you're working across a large code base, you obviously don't want to have to recompute all of the type information every time you come into it.
194
00:22:57.335 --> 00:23:00.235
And then there's also the question of being able to
195
00:23:00.940 --> 00:23:03.760
particularly if you're in exceedingly large code base,
196
00:23:04.220 --> 00:23:08.960
brings up the possibility of being able to share that state information across developers
197
00:23:09.485 --> 00:23:21.020
where you're you're working on different machines. And I'm wondering if you can talk to some of that state management aspect of Pyre and how you think about being able to generate that initial state and then maintain it and possibly propagate it for sharing?
198
00:23:21.560 --> 00:23:33.740
Yeah. That's a great question. I think that's something that we care a lot about. I mean, you can have a fast cold start, but it's still gonna be on the order of minutes on a massive, you know, multimillion line code base. So what we really want is for
199
00:23:34.200 --> 00:23:38.620
changes to give you results in seconds or less than a second, ideally.
200
00:23:38.920 --> 00:23:40.955
What we essentially do is we have this
201
00:23:41.515 --> 00:23:45.455
pretty neat, like, layering of dependency tables. So
202
00:23:45.835 --> 00:23:49.455
every single step that I had described before, so, you know, parsing, preprocessing,
203
00:23:50.210 --> 00:23:51.990
all the layers of environment building,
204
00:23:52.290 --> 00:23:53.350
and then type checking.
205
00:23:53.810 --> 00:23:55.990
They each rely on certain
206
00:23:56.370 --> 00:24:18.595
artifacts produced by a previous step or a previous layer, And we maintain tables that track the, essentially, the fetches or reads of things that were produced from a previous step. And this essentially builds out, like, as we do the calculations, builds out a dependency table based on, you know, in actuality, like, what did this calculation need. And so when something changes in the source,
207
00:24:19.135 --> 00:24:20.515
we can really quickly
208
00:24:20.895 --> 00:24:25.475
tell, like, okay, what changed in the app checks and tax tree? And then we can recompute
209
00:24:26.400 --> 00:24:30.659
no more or no less than exactly what is necessary in order to
210
00:24:30.960 --> 00:24:31.860
get an updated
211
00:24:32.400 --> 00:25:08.300
set of type errors. And this problem this wasn't our original solution either. Like, we used to have a system where we would track dependencies on a module level, but that would mean that if you change something in a very interconnected module, maybe you even change something that doesn't really matter, like, that
function itself or that, like, attribute itself isn't that interconnected, but, you know, its wrapping scope is, you would end up triggering type checks of just all these dependencies because, yeah, they depend on this module and name. Right? They import this thing, and then that would just be really slow. So this dependency table setup allows us to both with, like, really high,
212
00:25:08.680 --> 00:25:10.300
like, guarantee for reliability
213
00:25:11.025 --> 00:25:19.799
and with really fast speed, like, handle incremental updates. So, yeah, that's how we do incremental updates and all of the, like, environment state is saved on the server
214
00:25:20.179 --> 00:25:31.155
from the initial cold start. So then we're listening for file system changes, and then we have this server that like, this long running process that grabs that change and does this sort of dependency table informed recomputation.
215
00:25:31.855 --> 00:25:34.260
We can also save that state. So we have, I guess,
216
00:25:34.660 --> 00:25:47.855
intuitively, they're called safe states where we can generate this cold start, like, basically, the server state of the memory and save that. And we have done something in Instagram where for, like, shared commits, like, basically, published commits,
217
00:25:48.235 --> 00:25:50.895
we will generate these things async, and then
218
00:25:51.279 --> 00:25:54.980
multiple developers who might be developing on just, like, 1 or 2 commits above
219
00:25:55.520 --> 00:26:09.570
this shared published commit just grab that appropriate safe state from storage and can essentially start with an incremental check rather than starting with a cold start. As far as the kind of time space trade off, I'm wondering what the
220
00:26:10.030 --> 00:26:28.769
storage cost of that stateful type information is in relation to the code base that it pertains to? So, like, are we talking where you have the code base and maybe the type information is half the size, a quarter of the size? I'm just wondering what the kind of relative scale is of the storage space that's required to be able to maintain that information.
221
00:26:29.470 --> 00:26:38.845
Oh, it's not okay. I don't have actually accurate number here, so I won't guess, but it's much smaller. So there was not any, like, real storage concern with storing.
222
00:26:39.145 --> 00:26:41.085
We did, like, I think, 1 in every
223
00:26:41.690 --> 00:26:45.549
10 commits or something, and only for the past couple days.
224
00:26:45.850 --> 00:26:49.230
And so that was quite small. Like, we didn't have to
225
00:26:49.745 --> 00:26:58.725
really petition for extra storage or, you know, it's really special casing, the internal infrastructure we have for for storing and fetching things. It doesn't remember
226
00:26:59.270 --> 00:27:12.775
any of the source code itself. It remembers, like, basically, the the output of the environment building phase. So a lot of these are just tables of, like, globals and type hierarchies and things like that. So the space needs
227
00:27:13.315 --> 00:27:24.965
weren't huge, but then again, it also wasn't small enough that we could just store every single commit for quite a long time. And there also are a lot of projects where, you know, for example, if you're doing development on, like, a shared
228
00:27:25.424 --> 00:27:27.365
server that's warmed up for you beforehand,
229
00:27:27.825 --> 00:27:31.365
we don't even really need the save state for that project. Like, we can just
230
00:27:32.080 --> 00:27:42.905
modify the warm up process for a developer server. That just warms up your type checking beforehand, and you don't really have to deal with the system at all. Another interesting aspect of this
231
00:27:43.605 --> 00:27:45.465
problem space is that
232
00:27:46.005 --> 00:27:55.620
because of the fact that the Python type annotations and type definitions is a moving target and has been for several releases now, I'm wondering how that has
233
00:27:55.920 --> 00:28:24.680
impacted the work that you're doing on pyre being able to keep up with those changes in the ways that type annotations are specified, the types of types that are available, and, you know, the introduction of the typing module, and then the subsequent, you know, additions to it and changes where you can actually just use the built in name of that type without having to use the capitalized version and just all those kind of evolutions that we're going through and some of the ways that you're engaging with the Python developers and the Python community to help maybe shape that dialogue?
234
00:28:25.300 --> 00:28:31.635
I would hardly call it, like, keeping up with a changing system so much as, like, we're oftentimes the ones proposing changes.
235
00:28:32.135 --> 00:28:37.795
I think it's pretty exciting that the Python type system in many ways is really young, and
236
00:28:38.180 --> 00:28:40.920
it's changing a lot, and there are a lot of use cases
237
00:28:41.300 --> 00:28:51.005
and, you know, user pain points that we get to hear about, try to solve, and then eventually think of ways to really express this better, maybe
238
00:28:51.305 --> 00:28:56.370
more precisely or more clearly or more simply in the type system, and then bring these proposals
239
00:28:56.830 --> 00:29:06.075
to the open source typing community and write PEPs. So we write a lot of PEPs, actually. And so I guess we we kind of think of it as definitely a privilege that we can
240
00:29:06.455 --> 00:29:09.434
mold the type system that we're implementing a type checker against.
241
00:29:09.815 --> 00:29:10.315
And
242
00:29:10.770 --> 00:29:21.955
oftentimes, we even implement things before they get accepted as, like, a proof of implementation, like, get feedback on, you know, a lot of users actually using this in real Python code, and that actually
243
00:29:22.335 --> 00:29:23.634
really helps the evolution
244
00:29:24.014 --> 00:29:30.790
or ability
to accept the PEP with clear eyes on how this pans out. So, yeah, that is a big part of our work and something I really enjoy.
245
00:29:31.169 --> 00:29:39.024
And it's also pretty neat to see kind of, like, how the sausage gets made in terms of changes to the language. The community is really great,
246
00:29:39.404 --> 00:29:42.144
and it's really interesting getting to also weigh in on
247
00:29:42.445 --> 00:29:46.865
other proposals or other pain points and and see the type system change a lot, honestly,
248
00:29:47.200 --> 00:29:59.705
even over the past few years. But it's changed like crazy since 484 has been pushed out. Like, at that time, it was just like a comment style convention, really. So the rapid changes are really cool, and we're kind of at the point where
249
00:30:00.085 --> 00:30:03.144
we're, like, pushing a lot of those changes, which is a lot of fun.
250
00:30:03.519 --> 00:30:06.340
Another area that's been seeing a lot of growth and evolution
251
00:30:07.039 --> 00:30:12.340
alongside those changes to the typing system is the level of developer tooling and
252
00:30:12.775 --> 00:30:14.635
the integrations with that type system
253
00:30:15.015 --> 00:30:20.640
and how that manifests in terms of the developer experience. I'm thinking, in particular, things like editor integrations,
254
00:30:20.940 --> 00:30:27.600
language server protocol, in implementations. And I'm wondering how that has also shaped some of the
255
00:30:27.945 --> 00:30:36.605
feature direction and the areas of focus on Pyre for being able to work alongside some of those capabilities and being able to match some of the developer
256
00:30:37.000 --> 00:30:46.845
expectations of saying I've got my editor. I want it to tell me when I'm typing the wrong thing or when I'm using this variable in the wrong way. I guess editor integration for type results
257
00:30:47.305 --> 00:30:48.025
in general is
258
00:30:48.745 --> 00:30:52.045
was a was and remains, like, a really big priority because that is the primary
259
00:30:52.345 --> 00:30:55.539
interface that most people use to interact with Pyre.
260
00:30:55.840 --> 00:30:59.460
But there are also a lot of different applications for developer tooling
261
00:30:59.840 --> 00:31:05.675
that are made better by types. So, yeah, like you said, little things like go to definition, like hover,
262
00:31:06.135 --> 00:31:06.635
autocomplete,
263
00:31:06.935 --> 00:31:11.980
you know, like a lot of these, yeah, code navigation tools, code modding tools, also just
264
00:31:12.299 --> 00:31:13.120
smarter linters.
265
00:31:13.500 --> 00:31:26.815
So for Pyre, we've developed a query interface where a lot of these tools can ask of running Pyre server, not just for type results, but, you know, it's already doing the work of, like, listening to file system changes and updating its its understanding,
266
00:31:27.195 --> 00:31:44.015
right, incrementally. And you can also ping this server for, like, live results about what's the type of this thing at this location, or tell me if this is a subclass of that, or, yeah, tell me all of the names of something. So that has been 1 way that we're trying to do this integration, but a lot of this focus is also,
267
00:31:44.395 --> 00:31:47.375
like, something we're currently working on. So we really want to,
268
00:31:47.820 --> 00:31:57.395
like, support first class a lot of these kinds of linters or even additional analyses that kind of reuse the back end of the type checker and answer some slightly
269
00:31:57.695 --> 00:32:00.195
similar but not quite type system related questions
270
00:32:00.655 --> 00:32:07.900
and also support code navigation tooling. So, yeah, I think that there's, like, a really big space, honestly, in everything in the Python development
271
00:32:08.679 --> 00:32:20.370
workflow above the runtime that I think having, like, a a tool that has deep semantic understanding of control flow and the entirety of your project can provide just a lot of value in so many different ways. Absolutely.
272
00:32:21.390 --> 00:32:26.929
And as somebody who has been working with the Python community to, you know,
273
00:32:27.335 --> 00:32:29.915
understand and evolve the type system.
274
00:32:30.295 --> 00:32:38.260
I'm wondering what you see as being some of the strongest aspects of Python's approach to typing and some of the opportunities for
275
00:32:38.640 --> 00:32:49.904
improvement or some of the areas where you think the community has the potential to grow and improve upon the existing foundations that have been set over the past few releases?
276
00:32:50.605 --> 00:32:51.085
I would say
277
00:32:51.970 --> 00:32:54.789
I guess in some ways, I think the flexibility
278
00:32:55.090 --> 00:32:57.270
of the type system and the fact that it's
279
00:32:57.650 --> 00:33:00.070
like a kind of a living thing that's
280
00:33:00.635 --> 00:33:01.135
growing
281
00:33:01.435 --> 00:33:02.255
pretty quickly,
282
00:33:02.715 --> 00:33:04.895
I might describe that as both the
283
00:33:05.275 --> 00:33:05.775
strongest
284
00:33:06.155 --> 00:33:07.455
or kind of most impressive
285
00:33:08.130 --> 00:33:20.645
part of the type system, but also, like, maybe the reason why there's so much room for improvement. So I think it's pretty impressive, honestly, that we can design, like, a gradual type system that can provide a lot of soundness and value
286
00:33:21.025 --> 00:33:21.525
without
287
00:33:21.825 --> 00:33:25.240
stifling the dynamic language it was kind of tacked onto.
288
00:33:25.540 --> 00:33:28.520
I think when it comes to opportunities for improvement,
289
00:33:29.140 --> 00:33:37.005
I think there are kind of 2 directions, and sometimes they pull at each other. 1 of those being more expressability. Like, there are,
290
00:33:37.465 --> 00:33:45.520
you know, a lot of cases still that can't be expressed very well in the type system, and a lot of them are in, like, the numeric
computing or,
291
00:33:45.980 --> 00:33:46.800
like, tensor
292
00:33:47.180 --> 00:33:50.320
typing areas where you need type arithmetic and
293
00:33:50.655 --> 00:33:54.995
a lot of other constructs that just, you know, the type system as it is can't fully express.
294
00:33:55.295 --> 00:34:10.645
The other axes I was mentioning is, like, we don't want to detract from the cleanliness and the simplicity of Python and its syntax, and we really want types to be, like, kind of, like, augmenting the clarity and the readability of the language that I think is 1 of Python itself, like 1 of its
295
00:34:11.025 --> 00:34:18.760
points of pride, and like strong suits. So I think those 2 things are both ways that the type system can still improve. Like, a lot of peps are either
296
00:34:19.220 --> 00:34:19.720
expanding
297
00:34:20.020 --> 00:34:20.520
expressiveness
298
00:34:20.820 --> 00:34:21.720
of the type system,
299
00:34:22.180 --> 00:34:29.285
or they're trying to take something that can already be expressed, but kind of in a clunky way, and make it more sleek, more Pythonic.
300
00:34:29.585 --> 00:34:36.790
I guess a recent example of this that comes to mind is the self type I don't remember the PEP number off the top of my head, but it's 1 of the recent ones that's in 311.
301
00:34:37.270 --> 00:34:41.610
11. It really reduces the amount of boilerplate in order to use type variables
302
00:34:42.230 --> 00:34:51.964
to bind to the type of self. So things like that where you can, you know, Python's very intuitive and you want you want the type system to reflect that, you know, like, what you think this
303
00:34:52.265 --> 00:34:58.040
probably should be structured as is kind of just what works. So, yeah, I think there's a lot of room for improvement.
304
00:34:58.580 --> 00:35:12.130
In terms of Python's investment in the type system and to your point of some of the earlier investments in projects like Flow and Hack, and I know that the Ruby community has started investing in adding some type annotation capabilities.
305
00:35:12.910 --> 00:35:15.170
I'm wondering what you see as some of the
306
00:35:15.630 --> 00:35:16.130
juxtaposition
307
00:35:16.510 --> 00:35:24.005
of Python's approach of wholly adopting typing as a core capability in the language where it's a fully supported
308
00:35:24.545 --> 00:35:36.560
syntax and feature and something that is exposed for tools like Pyre, etcetera, to be able to build on top of versus some of the things like Flow or TypeScript that is an entire language over and above JavaScript
309
00:35:36.974 --> 00:35:46.435
or the the work being done on Hack where it's not something that is being folded into the core language definition. Just some of the ways that that
310
00:35:47.040 --> 00:35:49.140
manifests as far as the broader community
311
00:35:49.520 --> 00:35:52.340
adoption and availability of tooling and support?
312
00:35:52.800 --> 00:36:04.810
You know, we've run into some implications of runtime evaluations of of types recently. So types are actually evaluated at runtime even though they're not validated. So we've kind of realized this
313
00:36:05.190 --> 00:36:07.130
with a lot of unexpected pain,
314
00:36:07.430 --> 00:36:10.170
perhaps when we propose to stop evaluating
315
00:36:10.515 --> 00:36:28.880
types at runtime, for performance reasons and, you know, some other trade offs. And we discovered like, the typing community, like, to our surprise, discovered that there were a whole lot, like, a whole set of of tools and applications and projects and libraries that, like, came out of the community saying, like, no, we rely on having these available at runtime.
316
00:36:29.245 --> 00:36:42.350
And so, like, you can't do this. So that, you know, kicked off a whole other discussion around, like, how yeah. Like, what are the trade offs and, like, when and how is this type of value make sense? It poses some issues too with, like, forward references and things that maybe other type systems
317
00:36:42.890 --> 00:36:46.030
won't struggle with. That's 1 aspect that might be different.
318
00:36:46.345 --> 00:36:49.325
And I think in some ways too, it it is nice that
319
00:36:50.185 --> 00:36:53.244
the Python steering council and, you know, other, like,
320
00:36:53.609 --> 00:36:54.990
people who are responsible
321
00:36:55.290 --> 00:36:59.930
for sort of distilling and reflecting the community or the desires of the community,
322
00:37:00.730 --> 00:37:02.109
like, what they want from Python,
323
00:37:02.445 --> 00:37:09.185
have, like, a a lot of say and a lot of concerns with every change we propose to typing. There's a lot of
324
00:37:09.540 --> 00:37:14.280
syntax that is it would be nice to have maybe to express type annotations
325
00:37:14.580 --> 00:37:19.945
and more, you know, in more succinct ways or cleaner, quote, unquote, maybe, like, shorter ways. But,
326
00:37:20.405 --> 00:37:24.985
you know, adding that syntax would create a lot of complications for the parser and the runtime because
327
00:37:25.285 --> 00:37:42.895
that's actually part of the language. You can't just, like, throw in some angle brackets in the type and call that call that fine. Like, that's just part of the type system. Like, that actually is very difficult to do in Python because we I don't know if a lot of people actually want angle brackets brackets introduced into the syntax. It could bleed into other things. They could wind up getting picked up by other runtime
328
00:37:43.275 --> 00:37:48.950
features, etcetera. So it does make changes maybe a little bit harder, but I do think it kind of keeps the type system
329
00:37:49.410 --> 00:37:55.110
bound more tightly maybe to the rest of the language, both in terms of, like, syntax and
330
00:37:55.625 --> 00:38:03.484
style and readability, things like that. Yeah. That's definitely an interesting point as well, particularly for things like Flow or Hack where
331
00:38:03.829 --> 00:38:16.225
it's a layer on top of the underlying language, where if that underlying language decides to change their syntax and it happens to conflict with some of the syntax that was developed for the type annotations or the way that you represent that type information,
332
00:38:16.925 --> 00:38:19.585
then all of a sudden you have to do a whole huge refactor
333
00:38:19.970 --> 00:38:30.335
that because of the fact that the change was made that's outside of your control, where being part of the language community and something that is directed by the core developers and the broader ecosystem,
334
00:38:30.955 --> 00:38:41.270
it does have to maintain those same idioms. It does add some constraints and slows things down, but it makes sure that you don't have something that breaks all of a sudden because of something outside of your control.
335
00:38:42.450 --> 00:38:43.990
And in terms of
336
00:38:44.290 --> 00:38:57.530
your experience of working on the PyRE project and working with people who are using it for their day to day development and interaction with their development processes, what are some of the most interesting or innovative or unexpected ways that you've seen Pyre applied?
337
00:38:58.070 --> 00:38:59.610
There are a lot of different,
338
00:39:00.310 --> 00:39:07.155
you know, tools and structures that you end up needing when you, like, scale out Python to support huge production systems.
339
00:39:07.695 --> 00:39:12.355
And so there are, actually, I think are quite a lot of innovative ways that you can make
340
00:39:12.830 --> 00:39:15.730
semantic understanding of control flow, like, quite
341
00:39:16.190 --> 00:39:16.690
applicable.
342
00:39:17.230 --> 00:39:19.570
I think the first thing that comes to mind is
343
00:39:19.975 --> 00:39:23.995
is our effort to detect security vulnerabilities. So I've mentioned this before,
344
00:39:24.295 --> 00:39:25.115
you know, but
345
00:39:25.415 --> 00:39:30.720
in that context, I was really talking about building, like, additional static analysis that reuses the Python
346
00:39:31.260 --> 00:39:35.280
type checkers back end and, of course, reuses the type information to
347
00:39:35.580 --> 00:39:40.684
actually do, like, taint analysis, for example. But the type system and the type checker itself can actually
348
00:39:41.224 --> 00:39:43.805
also play a pretty neat role in catching and eliminating
349
00:39:44.265 --> 00:39:45.964
kind of entire classes of vulnerabilities,
350
00:39:46.320 --> 00:39:48.420
for example, like command or SQL injection,
351
00:39:48.720 --> 00:39:52.820
even in ways that just standard linters can't, like data validation, etcetera.
352
00:39:53.280 --> 00:39:55.380
For this topic, I would actually really recommend
353
00:39:55.934 --> 00:39:57.555
a talk by my coworkers
354
00:39:57.934 --> 00:40:01.154
at PyCon this past PyCon 2022. It's titled
355
00:40:01.615 --> 00:40:03.875
Securing Code with the Python Type System.
356
00:40:04.250 --> 00:40:06.349
It's given by, Pradeep Kumar Srinivasan
357
00:40:06.730 --> 00:40:18.474
and Graham Bleany. So maybe that's something we can link, but, that is a truck full of examples of like basically exactly this, innovative ways to apply the type system to catch security vulnerabilities
358
00:40:19.015 --> 00:40:32.055
via the type checker. So that's pretty neat and something that we've invested in a lot in and care a lot about. And then I think in addition to that, Pyre has frequently been pretty well positioned to just answer a lot of more complicated
359
00:40:32.435 --> 00:40:33.895
context based questions
360
00:40:34.275 --> 00:40:40.210
about the code base, either by exposing type information to other tools or, you know, inheritance structure, etcetera, or
361
00:40:40.670 --> 00:40:42.770
by just building some very simple
362
00:40:43.070 --> 00:41:02.099
additional analysis by itself. Like, we can detect, like, you know, dead code, unweighted, avoidables, etcetera, or even like more complicated questions about like how exceptions are thrown and whether they follow certain rules, you know, which functions throw what. So there are a lot of, like, I guess, glorified linters really that are also kind of innovative applications for
363
00:41:02.805 --> 00:41:06.185
the same basis of information that powers type checking.
364
00:41:06.645 --> 00:41:21.605
1 thing that I forgot to dig into briefly is for people who are adopting pyre for some of their development workflow, is it something where it's an either or, where you're only going to use pyre or you're only going to use mypyre, or do you see people
365
00:41:21.905 --> 00:41:25.605
using both or multiple different type checkers for different
366
00:41:25.905 --> 00:41:29.605
aspects of their kind of validation in their code base?
367
00:41:30.120 --> 00:41:36.860
No. I actually haven't seen very much use of both. Really, I think when a project is running both, it's in the process of transitioning
368
00:41:37.480 --> 00:41:52.430
to 1 or the other. And I think this might be because I think both type checkers are pretty up to standard when it comes to, like, feature completeness, so there isn't really a big class of errors that you might get in 1 and not in another.
369
00:41:52.810 --> 00:41:56.990
And then the annoyance probably of having, like, slightly different,
370
00:41:57.595 --> 00:41:58.415
like, location
371
00:41:59.195 --> 00:42:00.015
on errors
372
00:42:00.395 --> 00:42:12.310
in some cases where really they're exposing the same underlying problem. So it's not really that there is, like, either or would do just fine. But having both, I could see posing some issues when it comes to,
373
00:42:12.770 --> 00:42:29.869
suppressing errors, for example, like, all type checkers provide some escape hatches for, you know, either when you just don't have time to fix something or or something's, like, too dynamic and you want to just shut up the type checker.
So in those cases, you would put in line suppressions, and I feel like 2 type checkers can oftentimes make that really
374
00:42:30.250 --> 00:42:30.750
messy.
375
00:42:31.290 --> 00:42:31.790
So,
376
00:42:33.025 --> 00:42:49.790
no, I think usually people will pick a lane as far as I've seen, but I could be proven wrong. I haven't seen very many. In your work on developing the Pyre project and working in this type ecosystem for Python, what are some of the most interesting, unexpected, or challenging lessons that you've learned in the process?
377
00:42:50.215 --> 00:42:51.915
I really liked learning
378
00:42:52.535 --> 00:42:56.715
about, you know, how hard it is to scale a tool from, like, a greenfield
379
00:42:57.700 --> 00:42:58.839
implementation project
380
00:42:59.220 --> 00:43:00.279
to something that's
381
00:43:00.740 --> 00:43:04.759
actually in the core developer loop of, like, thousands of engineers every day.
382
00:43:05.205 --> 00:43:07.865
And there are a lot of, like, hard questions around how
383
00:43:08.325 --> 00:43:10.345
to measure, but maybe not, you know,
384
00:43:10.645 --> 00:43:11.865
overly numericize,
385
00:43:12.165 --> 00:43:14.920
like, user experience and developer speed?
386
00:43:15.300 --> 00:43:18.520
Like, how do you push against that in a falsifiable way?
387
00:43:18.900 --> 00:43:20.760
And, also, how do we scale our own
388
00:43:21.220 --> 00:43:22.200
internal infrastructure
389
00:43:22.500 --> 00:43:23.240
to be
390
00:43:23.735 --> 00:43:24.635
really a stable
391
00:43:25.415 --> 00:43:33.080
core developer team that that actually does support all of this traffic and and and we're, you know, in the blocking path of a lot of changes
392
00:43:33.460 --> 00:43:35.560
landing. So I I think that was a really interesting,
393
00:43:35.940 --> 00:43:47.535
just like scaling problem for us since we started from scratch. Like, we built this, and initially, it was we had, like, no users, and then we had Instagram, and now we have users just basically any Python project
394
00:43:47.835 --> 00:43:54.150
internally. So that's been really interesting. I think kind of what I mentioned before too, I've really enjoyed getting
395
00:43:54.690 --> 00:43:56.150
more exposure to
396
00:43:56.450 --> 00:44:01.235
the process of writing Peeps and just getting to know, like, kind of how
397
00:44:01.935 --> 00:44:05.715
Python is driven by just, like, open source community
398
00:44:06.415 --> 00:44:08.115
discussions and how much influence
399
00:44:08.839 --> 00:44:19.965
people who care can have on the language. I think that's been really neat and definitely something that was unexpected for me, you know, when I signed up to just start working on a type checker. So, yeah, I think that's been really cool.
400
00:44:20.345 --> 00:44:29.560
For people who are interested in being able to do some of this type validation and integrate that into their development work flow? What are the cases where Pyre is the
wrong choice?
401
00:44:30.100 --> 00:44:32.520
Yeah. That's a good question. I would say
402
00:44:32.980 --> 00:44:36.760
it could be not worth it if you're doing small, like, throwaway prototyping.
403
00:44:37.204 --> 00:44:43.545
If what you really value is, like, speed of iteration and really not the longevity or reusability of your code.
404
00:44:43.845 --> 00:44:48.560
And maybe also in really dynamic code Or, I guess, right now, if you're working with
405
00:44:48.940 --> 00:44:52.160
NumPy or ML pipelines, in those cases, I would say
406
00:44:52.460 --> 00:44:55.075
Pyre is not the right choice at the moment.
407
00:44:55.375 --> 00:44:57.474
There's actually a lot of complexity
408
00:44:57.855 --> 00:44:58.355
in,
409
00:44:58.815 --> 00:45:13.185
like, dynamic patterns that can be very, very elegantly expressed with types. So you might be surprised if you think your project falls under the too dynamic category, like, it might actually not. But, yeah, I think either too dynamic or, like, just not intended for reuse
410
00:45:13.725 --> 00:45:16.705
might not be the best choice for investing in types.
411
00:45:17.005 --> 00:45:21.610
And there's also kind of an interesting debate around how much value type annotations provide
412
00:45:21.990 --> 00:45:24.730
to Python when it's used as a learning language.
413
00:45:25.110 --> 00:45:52.695
So I've heard kind of both sides of this debate where some people argue that it it really helps with clarity and understanding to introduce types out of the gate to someone who's learning how to code for the first time, which Python is oftentimes, you know, used as that first language. And then, you know, other people argue that we really want the first experience to be, like, as close to English as possible. We don't want to make things more verbose. Like, even if those kind of expose the learner to what types are and, like, how values work in programming languages
414
00:45:52.995 --> 00:46:10.605
earlier, there is some debate there, and I can kind of see the argument on both sides. So maybe, you know, for certain new language learners, maybe types aren't the best choice yet. I don't know. I'm biased. So I I think types add clarity. So but I do see the other argument there. And, yeah, I guess, on the flip side, I think, you know, where pyre is
415
00:46:10.985 --> 00:46:16.445
the right choice in particular is probably just really large codebases that need to be maintained and need to be refactored.
416
00:46:16.970 --> 00:46:17.630
That's definitely
417
00:46:18.010 --> 00:46:19.470
where a type checker like Pyre
418
00:46:19.849 --> 00:46:21.630
shines and provides the most value.
419
00:46:22.010 --> 00:46:23.630
As you continue to
420
00:46:24.095 --> 00:46:26.755
work on the project and iterate on its capabilities
421
00:46:27.295 --> 00:46:33.315
and engage with the Python community on the future of typing, what are some of the things you have planned for the near to medium term?
422
00:46:33.940 --> 00:46:35.400
Yeah. So for the future of
423
00:46:35.700 --> 00:46:41.400
typing itself, just 1 example of an area where I feel like there could be a lot of potential for
424
00:46:41.985 --> 00:46:44.005
change and evolution is that,
425
00:46:44.305 --> 00:46:45.845
like, type system expressiveness
426
00:46:46.305 --> 00:47:00.220
around numeric computing or tensor typing. There are a lot of question marks in that space, but there are a lot of really smart people thinking about it and drafting proposals and trying to figure out how to do this in a way that adds value and doesn't add too much complexity.
427
00:47:00.625 --> 00:47:06.484
So I think that is definitely something to keep an eye on in terms of the future of the type system itself.
428
00:47:06.785 --> 00:47:09.200
And then I think for Pyre,
429
00:47:09.580 --> 00:47:17.440
I also just see a lot of room for, like, Pyre to provide value for different tooling applications. I think we talked about some of this before. So, like,
430
00:47:17.895 --> 00:47:23.275
code indexing, code navigation, linting, code mods, refactors, etcetera, like, all these tools. And we really want to see
431
00:47:23.734 --> 00:47:26.075
a very consistent, like, well supported
432
00:47:26.690 --> 00:47:31.670
development ecosystem that's just kind of a joy to work in for Python developers. So I think we're,
433
00:47:31.970 --> 00:47:32.869
in many ways,
434
00:47:33.705 --> 00:47:51.815
still many steps away from that. So I think that'll be something like, 1 thing that Pyre is focused on in addition to just making type checker faster and better. There are also some pretty neat applications, honestly, in the data use and privacy space. I won't get into the details of, but, you know, as Python's kind of used for more, like, massive and privacy sensitive products,
435
00:47:52.195 --> 00:48:00.590
having, you know, language level features and enforcement that can be done statically can also be pretty powerful and enable a lot of different
436
00:48:01.130 --> 00:48:10.725
guarantees and checks and things like that. Are there any other aspects of the Pyre project or applications of typing for development ergonomics and developer
437
00:48:11.265 --> 00:48:15.060
experience that we didn't discuss yet that you'd like to cover before we close out the show?
438
00:48:15.440 --> 00:48:31.310
Nothing comes to mind in particular, but I do definitely want to call out we sort of launched into the podcast assuming that types are given, and we're talking about type checkers. Right? The things that validate them. I think there's a whole discussion potentially to be had about, like, why types in lie in Python.
439
00:48:31.610 --> 00:48:41.585
And if that's something that's interesting, there are a couple talks that I would super recommend that I think we can link. They're all from PyCon, which I mean, there are a lot of great talks at PyCon, but in particular,
440
00:48:42.125 --> 00:48:52.160
Carl
Meyer had a 2018 PyCon talk called Type Check Python in the Real World. This is sort of a snapshot of of what Instagram was like when it was just converting over to
441
00:48:52.460 --> 00:49:06.700
Pyre, but was really largely still using Mypy, but it's really focused on, like, why types? Like, why do we bother to type check a huge untyped code base like Instagram and push it to, like, 99% typed where it's at now? And then also a really recent 1, so the 2022
442
00:49:07.480 --> 00:49:13.180
PyCon keynote by Lukas Langa is also really great. So, yeah, would recommend those for sort of more
443
00:49:13.555 --> 00:49:14.055
discussion
444
00:49:15.235 --> 00:49:23.369
on why types and how does it integrate with the developer experience in Python, and what are the trade offs, and what are the concerns? Why is it worthwhile?
445
00:49:23.750 --> 00:49:24.650
I think that's it.
446
00:49:24.950 --> 00:49:48.089
Alright. Well, for anybody who wants to get in touch with you and follow along with the work that you're doing, I'll have you add your preferred contact information to the show notes, and I'll definitely add those links that you mentioned in there as well. And so with that, I'll move us into the picks. And this week, I'm going to choose the new Lord of the Rings TV series that Amazon put out, the Rings of Power. I just watched the first couple of episodes of that, so definitely very excited to see how that develops.
447
00:49:48.454 --> 00:50:01.960
Definitely recommend that for anybody who is at all interested in the whole Lord of the Rings world and ecosystem franchise, however you wanna label that. And so with that, I'll pass it to you, Shannon. Do you have any picks this week? Well, first of all, I've been watching it too. It's very beautiful.
448
00:50:02.420 --> 00:50:04.440
Really impressive show. Yeah. I think
449
00:50:04.820 --> 00:50:05.320
I
450
00:50:05.835 --> 00:50:08.974
recently played King's Dilemma. It's a board game. I would
451
00:50:09.275 --> 00:50:11.615
really recommend it. It's very different from
452
00:50:11.915 --> 00:50:15.375
the style of, like, any other board game I've played. It's a narrative driven
453
00:50:16.060 --> 00:50:19.840
game where it's semi cooperative, but also very adversarial.
454
00:50:20.460 --> 00:51:00.675
You know, it's like you're kind of representing a house and you're making decisions basically on a king's council. You don't really even know the win condition of the game when you play. It's a legacy game, and I had a ton of fun playing this. If that kind of style sounds interesting to anyone, I would highly recommend it. Yeah. That definitely sounds interesting. I'll have to take a look at that game. I'm a fan of board games myself, so definitely we'll have to give that a look. So thank you again for taking all the time today to join me and share the work that you've been doing on Pyre and in the typing ecosystem for Python. It's definitely very interesting project and 1 that I've used myself a few times. So I appreciate all the time and energy that you and the other maintainers are putting into that, and I hope you enjoy the rest of your day. Thank you so much. Thank you for having me.
455
00:51:03.055 --> 00:51:16.055
Thank you for listening. Don't forget to check out our other shows. The Data Engineering Podcast, which covers the latest on modern data management, and the Machine Learning Podcast, which helps you go from idea to production with machine learning. Visit the site at pythonpodcast.com
456
00:51:17.075 --> 00:51:24.880
to subscribe to the show, sign up for the mailing list, and read the show notes. And if you learned something or tried out a project from the show, then tell us about it. Email hostspythonpodcast.com
457
00:51:26.300 --> 00:51:27.120
with your story.
458
00:51:27.500 --> 00:51:32.480
And to help other people find the show, please leave a review on Apple Podcasts and tell your friends and coworkers.