For the pastry, pulse the flour, baking powder, salt, butter and egg yolk in a food processor until the mixture resembles breadcrumbs. Add the grated parmesan and stir until well combined.
Gradually add the water, a tablespoon at a time, mixing continuously until the mixture just comes together as a dough. (You may not need to use all of the water.) Roll the dough into a ball, then wrap it in cling film and chill in the fridge for an hour.
Meanwhile, for the filling, bring a saucepan of salted water to the boil. Add the potato pieces to the pan and cook for 10-15 minutes, or until tender, then drain well and set aside.
Bring a separate large saucepan of water to the boil, add the sliced onions and cook for 2-3 minutes, or until softened. Drain well and return the cooked onions to the saucepan.
Sprinkle the onions with the flour and stir well to coat. Add the milk and cream and heat the mixture over a medium heat for 3-4 minutes, stirring continuously, until the liquid is smooth and has thickened slightly. Add the cooked potato pieces, grated cheese, mustard and cayenne pepper and stir well. Season to taste with salt and freshly ground black pepper, stir well, then set the filling mixture aside.
Preheat the oven to 180C/350F/Gas 4. Grease a deep 20cm/8in pie tin with butter. Add a small amount of flour, turn the tin to coat the base and sides of the tin, then shake out any excess.
When the pastry has chilled, roll out two thirds of it onto a clean, floured work surface, until it is almost twice as wide as the diameter of the pie tin. Using the rolling pin, lift the pastry and lay it over the pie tin to line the base and sides. Gently press the pastry into the corners of the tin, trimming off any excess, then prick the base of the pastry case several times with a fork.
Cover the pastry with a sheet of greaseproof paper and fill it with rice or dried beans. Bake in the oven for 10-15 minutes, or until the pastry is pale golden-brown. Remove from the oven, discard the beans and greaseproof paper and set the pastry aside to cool. When cool, pour the pie filling into the pastry case.
Roll the remaining one third of the pastry out onto a clean, floured work surface until it is slightly larger than the diameter of the pie tin. Brush the rim of the cooked pastry case with some of the beaten egg and place the pastry lid on top of the pie. Trim off any excess pastry. Seal the pastry lid to the pastry case by crimping the edges of the pastry lid with a fork.
With a knife, make two small holes in the centre of the pastry lid to allow steam to escape. Brush the pastry lid with the remaining beaten egg, then transfer to the oven and bake for 25-30 mins, or until golden-brown.