Context. The atmosphere of the Sun is permeated by a vast amount of magnetic flux that remains invisible in magnetograms based on the Zeeman effect. A model-independent way of measuring weak hidden magnetic fields makes use of the differential Hanle effect on the scattering polarization of molecular lines with different sensitivities to magnetic fields. Aims. The observed line scattering polarization steeply increases at the solar limb. Here we are interested in interpreting observations performed at the solar limb, where plane-parallel semi-infinite geometry is not valid. The main reason is that the sphericity of the atmosphere means that the line-of-sight optical path intersects only a finite part of the solar atmosphere. In this paper we revisit the modeling of scattering polarization in two molecular lines of C 2 and MgH in the spectral range from 515.60 nm to 516.20 nm, where observations performed both inside and above the solar limb are available. Methods. The solar atmosphere is described by a one-dimensional, spherically symmetric medium following either the FALC or the FALX quiet Sun model. Both the line and background continuum scattering polarizations are computed by means of the "along-theray" approach. We assume a two-level atom formalism for the line source function, and we compute the molecule number densities and line opacities assuming LTE. We estimate the elastic and inelastic collision rates by fitting the line intensity and linear polarization in several couples of lines of the Second Solar Spectrum Atlas. Results. The limb variations of scattering polarization, both in the lines and in the continuum, are strongly modified when the sphericity of the solar atmosphere is accounted for. We show that the line polarization goes through a maximum at 0.4 above the limb, for both MgH and C 2 lines. The contribution of the line rapidly goes to zero at a larger limb distance, but continuum polarization keeps increasing. The maximum polarization rates have an amplitude of 2% to 2.5% when the FALC model is used, which agrees with previous observations, whereas the FALX model leads to much higher rates. We then investigate the Hanle effect of microturbulent magnetic fields on the C 2 line linear polarization. We show that polarization observed close to the limb would provide valuable diagnostics of weak magnetic fields in the region of the temperature minimum.