That particularly piece of code is so wrong on so many levels. In fact, it was the impetus for me to fork PyROOT, b/c that’s what cancerous bitrot looks like.
The whole cppname business was completely rewritten in cppyy master and this particular function is not needed in the first place, but to have a localized fix, at least it should not only add the ‘const’, but also push the Py_DECREF two statements down. Either way, the scope id is a data member of the type instance, so GetScope() is completely superfluous.
You should probably also replace ‘_PyObject_GC_TRACK’ by ‘PyObject_GC_Track’ (in Pythonize.cxx). The former is a macro version of the latter, but accesses a variable that is no longer exported in 3.7, leading to a missing symbol (_PyGC_generation0). This was the only issue I found in cppyy master to support 3.7 (fixes are in repo; to be released soon enough).
There used to be a performance improvement, but I see no adverse effect today by replacing the macro with the function call.