In a medium saucepan, whisk together the sugar, cornstarch, cocoa powder, salt, and optional espresso powder.
In a separate bowl, whisk together the whole milk, heavy cream, and egg yolks until smooth.
Gradually whisk the milk mixture into the dry ingredients until no lumps remain.
Place the saucepan over medium heat and cook, whisking constantly, until the pudding thickens, leaves visible whisk trails, and large bubbles slowly break the surface.
Reduce the heat slightly and continue whisking for 30 to 60 seconds.
Remove the saucepan from the heat.
Add half of the chopped chocolate and let it sit for 1 minute. Whisk until completely melted.
Add the remaining chocolate and whisk until smooth.
Whisk in the butter until fully incorporated and glossy.
Stir in the vanilla extract.
For an extra silky filling, strain the pudding through a fine-mesh sieve.
Pour the pudding into the completely cooled crust and smooth the top with a spatula.
Let the pie cool at room temperature for 10 to 15 minutes.
Press plastic wrap directly onto the surface of the pudding.
Refrigerate for at least 8 hours, preferably overnight.