Slice the pumpkin or squash in half and scoop out the seeds and fibres. Cut each half into thick segments, as if you were slicing a melon.
Warm the oil in a baking dish over a moderate heat, place the segments cut side down and fry until the underside is golden brown, a matter of 5 minutes, then turn and cook the other side.
While the pumpkin browns, peel and halve the onions then slice each half into six pieces. Lift the pumpkin from the dish and set aside.
Put the onion into the hot oil and cook for 10 minutes or so, stirring regularly, until it is soft and pale gold. Add the thyme sprigs, a little salt and some ground black pepper. Set the oven at 200C/gas mark 6.
Return the pumpkin to the dish, then pour in the vegetable stock and bring to the boil. Lower the heat, cover with a lid, and leave to simmer for 20 minutes. Drain the beans then add them to the stock.
Replace the lid and transfer to the oven, leaving it to bake for 45 minutes.
For the final 10 minutes of cooking, remove the lid. Serve in shallow bowls, ladling the thyme-scented stock over the slices of pumpkin and spoonfuls of beans.