WHAT does a socialist say when they hear a group of striking workers start chanting: “I’d rather be a n****r than a scab”? It's a problem Mark Thomas explores in his play Red Shed at the Edinburgh Festival. And it’s complicated. He's also had to come to terms with the fact that working-class voters in Wakefield, where the eponymous shed is located, voted overwhelmingly for Brexit, and that many of them believe immigration should be halted.

In the past, socialists tended to avert their eyes from racist or homophobic attitudes among the working class, or tried explain it away as false consciousness. But this is becoming much harder now that industrial politics has fallen into decline, along with the trades unions, and the Left, in England at least, has become preoccupied – and even defined – by the politics of identity: by issues of gender, race and sexuality.

Middle-class left-wingers, especially women, are quite rightly intolerant of sexist and homophobic attitudes wherever they arise. But there is a tendency to treat white working-class males as a repository of Neanderthal attitudes. Well, they whistle at women in the street, read the Sun, wave the flag, watch Top Gear and laugh at jokes about foreigners. Campaigns such as No More Page Three can look like an attack on white working-class men in general.

Some believe the demonisation of the white working class has gone too far – even that the obsession with identity politics has obscured the fact that the common enemy is capitalism. In an article in the Guardian, the left-wing journalist, Owen Jones, says that the Labour Party is alienating working-class voters by treating them as if they were all “knuckle-dragging bigots”. He suggests that the party must turn the focus back on to class and away from abstractions such as equality diversity, sustainability, which are beloved by middle-class radicals.

Now, this is very sensitive territory. Jones obviously doesn’t mean that Labour should condone or tolerate racism or homophobia – he is himself an outspoken advocate of LBGT rights and regards himself as a feminist. But he clearly thinks there should be less censorious, finger-wagging over the attitudes of the white working class and more of an effort to understand where they are coming from. This overlaps with a common criticism of Jeremy Corbyn that the Labour leader is guilty of imposing a politically correct form of metropolitan politics on the party and destroying its electoral base – handing whole areas of England to Ukip.

Ex-Labour Party members like the Spectator's Rod Liddle and Janan Ganesh of the Financial Times say that the “Islington” strand of Labour is too preoccupied with black and ethnic minorities and has lost touch with the interests of core voters. To combat right-wing nationalists like Ukip, they say, Labour needs to become a bit more, well, pro-British, and recognise and accept that immigration has hit the living standards of many low-paid workers. Research by the Resolution Foundation has indeed confirmed that immigration has depressed the wages of low-paid workers, though not nearly as much as suggested by some tabloid newspapers.

Supporters of the conservative-leaning Blue Labour, including the academic Maurice Glassman, think that the left in general has alienated the working class by its hostility to patriotism and by appearing always to defend benefit claimants, prison reform and sexual minority groups. He believes that the New Labour of Tony Blair – “tough on crime” and so on – was much closer to the instincts and sensibilities of working-class voters than the metropolitan Labourism of either Ed Miliband or Jeremy Corbyn.

Now, all this might seem somewhat remote to us in Scotland, where New Labour never took root, and where immigration has never been the toxic political issue it is south of the Border. Of course, many Labour people, both old and new, used to regard Scottish nationalism as a form of semi-racist politics that divided the working class by pitting Scots against English. Not all of them still do. In fact some of the leading figures on the Corbyn left, such as journalist Paul Mason and shadow cabinet minister Clive Lewis, are advocating some form of progressive alliance with the SNP after the next general election. This is still heresy in Scottish Labour circles, where any co-operation with the hated nationalists would be seen as a betrayal of the tribe.

But really, the issue of identity politics is very different in Scotland and it is worth exploring why this is. Here, the Scottish National Party has had considerable success in colonising working-class politics to such an extent that it has almost made Labour politically irrelevant. Yet, the SNP is pro-immigration, advocates multiculturalism, and Nicola Sturgeon is very strong on gender equality, sustainable energy and LGBT politics – all the things that are supposed to be alienating working-class voters south of the Border.

Clearly, there is a different political culture in Scotland. But voter attitudes aren't all that different, as many unionists pointed out during the referendum. Only 15 years ago, Scotland was bitterly divided over the Keep The Clause campaign of Brian Soutar and Cardinal Winning, which sought to prevent homosexuality being treated as normal in Scottish schools. Only a decade ago, opinion polls suggested that a quarter of Scots believed that prejudice against minorities was acceptable.

However, opposition to immigration, even though it exists, is not a defining political issue in Scotland. There have been fewer migrants for a start, and historically Scotland's key demographic problem has been out-migration. But I don't think that fully explains it. The lack of Ukip-style politics has a great deal to do with political leadership and education by politicians like Nicola Sturgeon. And working-class support for the SNP and its values also has a great deal to do with patriotism. In Scotland, supporting your flag and your country is not seen as inherently right-wing, except by die-hard Labour tribalists.

The SNP has always been very careful to present itself as fighting Scotland's corner – putting Scottish interests first and last, but Nicola Sturgeon insists she is a “utilitarian” not an “existential” nationalist, and is mainly concerned with social justice. The First Minister has managed to ride the two horses of nationalism and social democracy without falling off. What used to be called “the dark side” of nationalism has been eclipsed by an ideal of Scotland as being a more equal and tolerant country than England. The First Minister has even made accepting asylum seekers a source of national pride.

Hateful people still exist in the SNP, of course. But I think we have to accept that prejudice and hatred exists in all classes and all nations. Working-class people should not be romanticised, deodorised, idealised and nor should Scots. They're just like everyone else. The left should of course challenge politically unacceptable views, but not get them out of proportion. There is a strand of radical politics, mainly on university campuses, that has confused argument with censorship and spends its time policing what it regards as offensive language. But you can't change society by moral righteousness. Nor are Brexit voters all racists. In the end, tolerance of people you disagree with is a sign of strength.