For Letitia James, politics has made quick and convenient bedfellows.

After Eric T. Schneiderman suddenly resigned in May as New York’s attorney general, it soon became clear that Ms. James, the New York City public advocate, was the favored choice of Gov. Andrew M. Cuomo to succeed him.

Within weeks, Mr. Cuomo endorsed Ms. James; the Democratic Party’s formal nomination quickly followed. The governor then held a fund-raiser for her with a minimum ticket price of $1,000. He invited her to appear with him at rallies for reproductive rights. And, in July, he brought Ms. James and several of his political allies on his fifth trip to Puerto Rico since Hurricane Maria.

As the other three Democratic candidates for attorney general have tried to distance themselves from Mr. Cuomo, Ms. James has fully embraced him. But at a time when prosecuting Wall Street, pursuing political corruption in Albany, and being willing to challenge President Trump and his administration are considered highly prized qualifications for the job, Ms. James’s strategy has been one of high rewards, but also some risk.

“Perhaps no criterion is more important right now than the capacity of the next attorney general to be independent,” said the former attorney general, Eliot Spitzer, under whose tenure Ms. James ran the office’s Brooklyn operations. “The occupant of that office must have the wherewithal to pursue cases against the most powerful forces without regard to political consequences.”