/-- The affine cover of a scheme. -/
def affineCover (X : Scheme) : OpenCover X where
  J := X.carrier
  obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose
  map x :=
    ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _)
  f x := x
  IsOpen x := by
    apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp
    apply PresheafedSpace.IsOpenImmersion.ofRestrict
  Covers := by
    intro x
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X✝ Y Z : Scheme
𝒰 : OpenCover X✝
f : X✝ ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f) g
X : Scheme
x : ↑↑X.toPresheafedSpace
⊢ x ∈
    Set.range
      ⇑((fun x =>
                (Nonempty.some
                      (_ :
                        Nonempty
                          (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                              (_ :
                                OpenEmbedding
                                  ⇑(Opens.inclusion
                                      (Exists.choose
                                          (_ :
                                            ∃ U R,
                                              Nonempty
                                                (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                                    (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                                  Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                            Spec.toLocallyRingedSpace.obj
                              (op
                                (Exists.choose
                                  (_ :
                                    ∃ R,
                                      Nonempty
                                        (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                            (_ :
                                              OpenEmbedding
                                                ⇑(Opens.inclusion
                                                    (Exists.choose
                                                        (_ :
                                                          ∃ U R,
                                                            Nonempty
                                                              (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                                                  (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                                                Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                                          Spec.toLocallyRingedSpace.obj (op R)))))))).inv ≫
                  LocallyRingedSpace.ofRestrict X.toLocallyRingedSpace
                    (_ :
                      OpenEmbedding
                        ⇑(Opens.inclusion
                            (Exists.choose
                                (_ :
                                  ∃ U R,
                                    Nonempty
                                      (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                          (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                        Spec.toLocallyRingedSpace.obj (op R)))).obj)))
              ((fun x => x) x)).val.base

Next tactic:
erw [coe_comp]