Last week, President Obama's approval rating hit 50 percent. That's a three-year high; the last time his approval rating was this strong was way back in May 2013.

The improvement is important, and not just for Obama's legacy. Presidential approval is one of the key indicators of the outcomes of presidential elections. When presidential approval rises, the chance of victory for the incumbent party goes up as well — so Obama's growing approval suggests that Democrats have a better chance to win in November.

When the president's approval rating is +4 in the summer before an election, the incumbent party is the favorite to win; when the president's approval is -4, the out party is favored. Obama's approval in the Real Clear Politics average at the moment is +0.4 — not great, but better than the negative approval numbers he was struggling with a year ago.

The question begs: Why? Why do more people suddenly approve of Obama? What exactly is he doing right?

Political scientists have been trying to figure out what drives presidential approval for years. Some studies have tied presidential approval inversely to gas prices, for example — and the low prices at the pump now could certainly be helping Obama. Presidential approval has also been linked to the stock market — and again, the rise of the market over the last month after a very rocky start to 2016 may be boosting the president.

Gas prices and stock markets are, of course, tied to the economy. In particular, they're highly visible factors that may affect the appearance, or feeling, of economic health. "What seems to affect presidential approval is not objective indicators of inflation or unemployment," Gisela Sin, a professor of political science at the University of Illinois Urbana-Champaign, told me. "Instead, the perception of economic conditions" is what drives presidential approval. People feel that the economy is better when they don't pay a lot at the gas pump. Good news on the stock market is reported in the media, and may improve people's sense of how the economy is doing.

And, of course, unemployment is actually down; when people are able to find jobs, they feel more positive about the president's party. This may be particularly important for Obama, according to Sin, because he is a Democrat. Democratic presidents' approval ratings tend to be more sensitive to unemployment; Republican presidents' tend to be more sensitive to inflation.

Party affiliation always powerfully affects approval rating, but Obama's numbers throughout his term have been particularly divided along partisan lines. And sure enough, his healthy approval rating in recent weeks has been fueled mostly by Democrats, according to Gallup. Obama is at 87 percent approval among members of his own party, which is 4 percentage points higher than his average approval rating with Democrats since 2009. His rating among Republicans and independents, on the other hand, is closer to his term average.

Partisanship may be responsible for Obama's improvement in other respects as well. In addition to the economy, the one factor that may most be helping Obama is the primary campaign. "Usually," Sin points out, "presidents compete with opposition political actors, and are the sole recipient of most of the opposition criticisms: emphasizing the unfavorable issues and downplaying the favorable ones." In other words, Obama's approval is usually weakened by the fact that every Republican who appears on television talks about how awful Obama is.

But political news in the last months has been dominated by the primaries. Republicans have been aiming their fire at Hillary Clinton and Bernie Sanders — and, perhaps most intensely, at each other. Republican actors have been so caught up in dealing with Donald Trump's insurgent candidacy, and with his violation of civic norms, that they've had trouble doing much of anything else. Elites like former presidential nominee Mitt Romney and New York Times columnist Ross Douthat have been forced to concentrate on denouncing Trump rather than denouncing Obama. Even the pro-Trump gutter press outlet Breitbart has been reeling after Trump's campaign manager allegedly assaulted one of the site's reporters, leading to an exodus of talent when the editorial department failed to stand behind her.

Here's the upshot: Republicans simply lack the energy and the resources to attack Obama at the moment, and that means he can present himself as statesmanlike and presidential without contradiction.

Republican fears that Trump might harm their chances in November, then, are entirely rational. The chaos and uncertainty he's sowed already appear to be damaging the party, and helping the Democratic president. "The public is not receiving a constant negative message about Obama," Sin told me. Instead, they're watching the Republican Party ritually tear itself apart. Democrats look at Trump and feel better about their party leaders in comparison. Republicans are so consumed with fighting over Trump that they aren't able to despise their opponents with the usual fervor. As long as Trump continues to surge, Obama and the Democrats are going to look pretty good in comparison. And that bodes well for the party's chances in the fall.