I remember visiting Havana in 2015 and browsing the book stalls around the Plaza de Armas. From a distance they looked inviting – like those you see along the Seine in Paris. But up close it became apparent that we were being duped. The books were standard issue hagiographies of Che Guevara and Fidel Castro, alongside the occasional biography of “Papa” Hemingway. Like going into a bar with a painted bookcase on the wall, it was an illusion of knowledge, a facade of enlightenment. Books are agents of freedom; they teach us to think and question. The book stalls in Havana made a mockery of that.

Among the many Cuban writers notably absent at those state-controlled book stalls was Renaldo Arenas, the gay dissident who catalogued the persecution of gay men under Castro’s regime, including his own arrest and solitary confinement in a one-meter-high cell. Arenas eventually escaped to the United States, part of the famous Mariel boatlift. Julio Capó Jr, an associate professor of history at the University of Massachusetts, has described it as, in part, a “homosexual purge”.

Ravaged by Aids, Arenas killed himself in 1990, shortly after completing his luminous memoir Before Night Falls. The book, coincidentally reissued this week in an elegant Penguin Classics edition, is an extraordinary testament to defiance and dispossession. Arenas was a wonderfully fluid writer, and Before Night Falls is brazenly sexy, filled with ribald anecdotes of his many sexual encounters. “We would bring our notebooks and write poems or chapters of our books, and would have sex with armies of young men,” he wrote. “The erotic and literary went hand in hand.”

That kind of thinking and behavior has always been at odds with leftwing revolutionaries. It is too hedonistic, too indulgent. As a student at college in the early 1990s I recall being told that gay rights were a bourgeois affectation. The coming revolution took precedence over identity politics. Gay men, in particular, were seen as silly dilettantes unable to apply themselves to the serious business of changing the world. There was a sense that we were possessed by the spirit of Oscar Wilde, and could only contribute witty bon mots where what was needed were “men” at the barricades. Like the heroic poses of Guevara or Castro on those book jackets in Plaza de Armas, the narrative of revolution was profoundly chauvinistic.

When Bernie Sanders doubled down on his old “not everything was bad” defense of Fidel Castro last weekend, citing things like Castro’s literacy programs, I thought of my fellow students from the early 90s. Although society has transformed since I left college, Sanders’ take on Cuba seemed marooned in the past. Cuba’s record on LGBTQ rights has improved in the last 20 years, but Castro was singularly ruthless in his persecution of gay men, lesbians and transgender people. Many of Arena’s friends were either jailed, forced to flee the country, or killed themselves. The rest curried favor with the regime by turning informants. To single out the country’s successes feels dangerously like a form of whitewashing. Just try to imagine a candidate extolling any aspect of Spain under Franco.

Although no one would argue that a literacy program is itself a bad thing, to ignore the indoctrination that went hand-in-hand with that program, the censorship of writers that fell afoul of the state, the blacklisting – and far, far worse – of queer artists like Arenas or Virgilio Piñera, seems more than tin-eared. It seems complicit in normalizing injustice. Literacy is only half useful if all you are allowed to read is communist propaganda. Just last year Reporters without Borders classified Cuba as 168 out of 180 countries in the world ranking of Press Freedom.

Of course, no thinking person, Sanders included, believes that Cuban literacy was worth the human cost, but it’s also likely that Cuba’s history of persecuting LGBTQ people wasn’t on his radar in 1980, when he first praised Castro’s record. To be fair, it wasn’t much on anyone’s radar. Most Americans were deeply homophobic themselves at the time. Dissidents like Arenas didn’t get asylum in the US because they were gay, but because they were seen as anticommunist.

Sanders is no homophobe. As mayor of Burlington, he marched in the city’s gay pride in 1983, and was among the lone senators to vote against Bill Clinton’s misguided Defense of Marriage Act that defined marriage as the union of one man and one woman. But there’s a sense in which his ideals, as in this case, can trip him up. Consistency is, of course, his greatest asset, but it can also be his greatest liability. Every now and then he might benefit from admitting that sometimes you get it wrong.