driver expression dot.product function
Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2


Settings:

Turn on register in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45




Additions: 
Original script has two mistakes.
1. Transformation matrix for converting to world space is 

object.matrix_world @ pose_bone.matrix


2. Vector myvec needs to be normalized.