Add py_safe function
Merge pull request #15636 from thatch45/py_safe

Add py_safe function