static final String sanitizeQualifiedName(TypeMirror type, PackageElement pkg) {
		if (type instanceof DeclaredType dt) {
			TypeElement el = (TypeElement) dt.asElement();
			PackageElement typePkg = getPackage(el);

			String name;
			if (pkg.equals(typePkg)) {
				name = sanitize(el.getSimpleName());
				Element parent = el.getEnclosingElement();
				while (parent instanceof TypeElement parentType) {
					parent = parent.getEnclosingElement();
					name = sanitize(parentType.getSimpleName()) + "." + name;
				}
			}
			else {
				name = sanitizeQualifiedName(el);
			}

			List<? extends TypeMirror> args = dt.getTypeArguments();
			if (args.isEmpty()) {
				return name;
			}
			Iterable<String> it = () -> args.stream()
					.map(paramType -> sanitizeQualifiedName(paramType, pkg))
					.iterator();
			return name + "[" + String.join(", ", it) + "]";
		}
		return sanitize(type, pkg);
	}
Makes the qualified name for the provided type Python safe if necessary<p/>

The provided package is used to check each type and generic components.

@param type the type to make Python safe
@param pkg the current package
@return the Python safe qualified type name
GhidraBuild/BuildFiles/Doclets/src/main/java/ghidra/doclets/typestubs/PythonTypeStubElement.java