theorem affineLocally_of_comp
    (H : ∀ {R S T : Type u} [CommRing R] [CommRing S] [CommRing T],
      ∀ (f : R →+* S) (g : S →+* T), P (g.comp f) → P g)
    {X Y Z : Scheme} {f : X ⟶ Y} {g : Y ⟶ Z} (h : affineLocally (@P) (f ≫ g)) :
    affineLocally (@P) f := by
  let 𝒰 : ∀ i, ((Z.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (Z.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (Z.affineCover.map i)).affineCover
  have h𝒰 : ∀ i j, IsAffine ((𝒰 i).obj j) := by dsimp; infer_instance
  let 𝒰' := (Z.affineCover.pullbackCover g).bind fun i => Scheme.affineCover _
  have h𝒰' : ∀ i, IsAffine (𝒰'.obj i) := by dsimp; infer_instance
  rw [hP.affine_openCover_iff f 𝒰' fun i => Scheme.affineCover _]
  rw [hP.affine_openCover_iff (f ≫ g) Z.affineCover 𝒰] at h
  rintro ⟨i, j⟩ k
  dsimp at i j k
  specialize h i ⟨j, k⟩
  dsimp only [Scheme.OpenCover.bind_map, Scheme.OpenCover.pushforwardIso_obj,
    Scheme.Pullback.openCoverOfRight_obj, Scheme.OpenCover.pushforwardIso_map,
    Scheme.Pullback.openCoverOfRight_map, Scheme.OpenCover.bind_obj,
    Scheme.OpenCover.pullbackCover_obj, Scheme.OpenCover.pullbackCover_map] at h ⊢
  rw [Category.assoc, Category.assoc, pullbackRightPullbackFstIso_hom_snd,
    pullback.lift_snd_assoc, Category.assoc, ← Category.assoc, op_comp, Functor.map_comp] at h
  -- Porting note: this previously ended with `exact H _ _ h` but that runs away
  -- explicitly specifying `f'` and `g'` in the `comp` and then using a `convert` (?)
  -- lets us get something
  let f' := Scheme.Γ.map (Scheme.OpenCover.map
      (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
        pullback.snd).op
  let g' := Scheme.Γ.map (Scheme.OpenCover.map (Scheme.affineCover (pullback f
      (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map
        (Scheme.affineCover Z) i))) j ≫ pullback.fst))) k ≫ pullback.snd).op
  convert H f' g' ?_
  

Proof state:
case mk
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
H :
  ∀ {R S T : Type u} [inst : CommRing R] [inst_1 : CommRing S] [inst_2 : CommRing T] (f : R →+* S) (g : S →+* T),
    P (comp g f) → P g
X Y Z : Scheme
f : X ⟶ Y
g : Y ⟶ Z
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover Z) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover Z) i) f).hom)
          i_1)
h𝒰 :
  ∀ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)).J) (j : (𝒰 i).J),
    IsAffine (Scheme.OpenCover.obj (𝒰 i) j)
𝒰' : Scheme.OpenCover Y :=
  Scheme.OpenCover.bind (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) g) fun i =>
    Scheme.affineCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) g) i)
h𝒰' : ∀ (i : 𝒰'.J), IsAffine (Scheme.OpenCover.obj 𝒰' i)
i : (Scheme.affineCover Z).J
j : (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))).J
k :
  (Scheme.affineCover
      (pullback f
        (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
          pullback.fst))).J
h :
  P
    (Scheme.Γ.map
        (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
            pullback.snd).op ≫
      Scheme.Γ.map
        (Scheme.OpenCover.map
              (Scheme.affineCover
                (pullback f
                  (Scheme.OpenCover.map
                      (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
                    pullback.fst)))
              k ≫
            pullback.snd).op)
f' : Scheme.Γ.obj (Opposite.op (Scheme.OpenCover.obj (Scheme.affineCover Z) i)) ⟶
  Scheme.Γ.obj
    (Opposite.op
      (Scheme.OpenCover.obj (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j)) :=
  Scheme.Γ.map
    (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
        pullback.snd).op
g' : Scheme.Γ.obj
    (Opposite.op
      (Scheme.OpenCover.obj (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j)) ⟶
  Scheme.Γ.obj
    (Opposite.op
      (Scheme.OpenCover.obj
        (Scheme.affineCover
          (pullback f
            (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) j ≫
              pullback.fst)))
        k)) :=
  Scheme.Γ.map
    (Scheme.OpenCover.map
          (Scheme.affineCover
            (pullback f
              (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i)))
                  j ≫
                pullback.fst)))
          k ≫
        pullback.snd).op
⊢ P (comp g' f')

Next tactic:
exact h