If you have the opportunity to start in Porto and end the trip in Lisbon, that would be good as it’s cooler in the north. I’ve been here the last three September’s and it’s quite warm. But, I’ve only seen 40C temps once and that was in August.
Plan on dressing for summer with maybe a light jacket for evenings. I also recommend accomodations with AC - especially in Lisbon.
And, I agree that warm weather is preferable to wet! Be sure to bring shoes with very good soles whether the weather is dry or wet. The cobblestones are a challenge for those of us who didn’t grow up walking on them...
Lastly, do some research on the elevators, escalators, funiculars, etc. in Lisbon - and one I know of in Porto. They are a great help in navigating the hills.