We consider the 6d (2, 0) theory on a fibration by genus g curves, and dimensionally reduce along the fiber to 4d theories with duality defects. This generalizes class S theories, for which the fibration is trivial. The non-trivial fibration in the present setup implies that the gauge couplings of the 4d theory, which are encoded in the complex structures of the curve, vary and can undergo S-duality transformations. These monodromies occur around 2d loci in space-time, the duality defects, above which the fiber is singular. The key role that the fibration plays here motivates refering to this setup as theories of class F. In the simplest instance this gives rise to 4d N=4N =4 Super-Yang-Mills with space-time dependent coupling that undergoes SL(2, ℤ) monodromies. We determine the anomaly polynomial for these theories by pushing forward the anomaly polynomial of the 6d (2, 0) theory along the fiber. This gives rise to corrections to the anomaly polynomials of 4d N=4 N=4 SYM and theories of class S. For the torus case, this analysis is complemented with a field theoretic derivation of a U(1) anomaly in 4d N=4 N=4 SYM. The corresponding anomaly polynomial is tested against known expressions of anomalies for wrapped D3-branes with varying coupling, which are known field theoretically and from holography. Extensions of the construction to 4d N=0 N=0 and 1, and 2d theories with varying coupling, are also discussed.