You will never be able to control what other people choose to discuss, unfortunately. You are fully within reasonable expectations to be able to say you dislike the topic. If you are at a social gathering, then it is socially polite for people to take into account that everyone enjoys themselves to a reasonable extent.
In general, you can make simple statements such as, "This is such a polarizing topic. Could we please just discuss something a little more fun and lighthearted?" In particular, if with family, I will add in something like how seldom I get to see them & I mostly want to laugh & catch up on one another's lives, and not dissect the problems of the world. This may not work as well in other arrangements that are more formal perhaps.
If asked point blank any question I do not wish to discuss I deflect. It's not just politics. I do it sometimes for sport, to make the point even. I have been asked if we are having any more children. I find this to be a very personal question for someone to throw at you in a group, so instead, I crack a joke by asking something of them that I find overly personal, such as "How much money did you make last year?" When they look confused then comes the punchline, said in good humor, "Oh I am sorry, I thought we were asking awkward questions, like a game. Oops".
How best to handle any given situation will depend on your personality type (if you aren't funny by nature, humor is likely out of the list of options). It depends on your relationship to the people within said conversation as well as the dynamic of the group. I have some family that we can have fascinating mutually respectful political banter for hours on end and everyone is enjoying it. On the other hand, I have other family that such a discussion leads to arguing & ruffled feelings in a matter of minutes (yet they don't have the good sense to avoid it). I used to work for someone with very strong opinions absolutely opposite of my own and he gravitated toward clients that were similar, or maybe they gravitated toward him? Either way, I was often subject to listening to them go on and on about things I absolutely was in opposition to. I generally remained quiet, said as little as possible, even at timetimes claimed ignorance to avoid having to take any stance. I might in such cases, when asked what I thought, say something like, "I am sorry. Listening to you all discuss it has been enlightening, but I am afraid that I don't feel as informed as I should be to even make any assessment on that. I definitely intend to look into it more." It
I am sorry. Listening to you all discuss it has been enlightening, but I am afraid that I don't feel as informed as I should be to even make any assessment on that. I definitely intend to look into it more.
It was not my place in that environment to make my boss or our clientele uncomfortable with my personal political views which literally had absolutely nothing to do with the business I was in. No one would have been better off for me having aired my opposition and very likely I would have alienated myself. The "best" way to handle it will always be relative to all such types of variations of circumstance. In business, I prefer maximum privacy on personal views. I don't really want to hear what other people think about issues that do not pertain to work and likewise, I would prefer not to share. If it's more familiar-peer situation or family I believe it is reasonable to ask for a change of topic, and people might initially act put out, but can most often seem to move past the initial reaction and stop using that topic.