how to test if there is a link to a specific node socket? Building a blender 2.8 helper addon to automatiz tasks, I need to test if a node is connected to Principled Alpha socket. If not, I will connect A RGB node.
I fail to check "if any node connected : do something" ...
following code works but I can't do anything if nothing connected found

for m in bpy.context.object.material_slots:    
mat = m.material
nodes = mat.node_tree.nodes    
for mat_node in mat.node_tree.nodes:
    if mat_node.type == 'BSDF_PRINCIPLED':
        print(mat.name + " "+ mat_node.name +" :" )            
        alphasocket = mat_node.inputs[18]
        #print(alphasocket)
        node_in = mat_node.inputs
        #print(node_in)      

        for n in alphasocket.links:               
            print(n.from_node.name +" connected to Alpha")
OK I've found out

for m in bpy.context.object.material_slots:
mat = m.material
if (mat.use_nodes):
    nodes = mat.node_tree.nodes
    links = mat.node_tree.links
    for n in nodes:
        if (n.type == 'BSDF_PRINCIPLED'):
            print(mat.name)
            alphasocket = n.inputs[18]
            if not(alphasocket.is_linked):
                print("No Alpha node!")     
            else:
                print("Alpha node connected")