This topic has been around for decades and there is no single answer. But there is nothing wrong with taking a lane especially if it is the safer option.
Everything depends on the environment, traffic, time of day, and most importantly what each rider is comfortable with.
Where I live there are bike lanes everywhere and they are well used. But there are also some canyon roads where you have to take a lane, there is no other option. Likewise there are some canyon roads with excellent shoulders and I have never seen a rider take a lane; and they are well ridden:
I do believe that the rise of gravel bikes and rail trails is a pretty clear indicator that riding in traffic is not a benefit. I exclusively rode mtb’s for a while after many years on the road and it was such a revelation.
John