From 3dd407ca4600ea5101421fa49332623d89bc640f Mon Sep 17 00:00:00 2001 From: James Knight Date: Sun, 24 Jul 2022 13:42:39 -0400 Subject: [PATCH] always default create optional environment for deprecated builders Builder implementation would originally always create an optional environment instance, which an extended builder's implementation could reference in their own `__init__` call. However, with the change [1] to support an `env` argument, there is no longer a guarantee that `self.env` will exist. This commit changes this to restore the creating of `self.env` if `env` if not passed in. [1]: 6ef22d261303ec07890305b300135c34952ca327 Signed-off-by: James Knight --- sphinx/builders/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 62a369a912..9f70582fca 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -89,10 +89,11 @@ def __init__(self, app: "Sphinx", env: BuildEnvironment = None) -> None: self.env: BuildEnvironment = env self.env.set_versioning_method(self.versioning_method, self.versioning_compare) - elif env is not Ellipsis: + else: # ... is passed by SphinxComponentRegistry.create_builder to not show two warnings. warnings.warn("The 'env' argument to Builder will be required from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) + self.env: Optional[BuildEnvironment] = None self.events: EventManager = app.events self.config: Config = app.config self.tags: Tags = app.tags