Skip to content

Commit 0e6c4cd

Browse files
authored
Ensure optional dependencies are optional (#2508)
1 parent e0dc757 commit 0e6c4cd

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

elasticsearch/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
try:
6767
from .serializer import OrjsonSerializer
68-
except ModuleNotFoundError:
68+
except ImportError:
6969
OrjsonSerializer = None # type: ignore[assignment,misc]
7070

7171
# Only raise one warning per deprecation message so as not

elasticsearch/serializer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from elastic_transport import OrjsonSerializer as _OrjsonSerializer
4646

4747
__all__.append("OrjsonSerializer")
48-
except ModuleNotFoundError:
48+
except ImportError:
4949
_OrjsonSerializer = None # type: ignore[assignment,misc]
5050

5151

noxfile.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ def format(session):
8484

8585
@nox.session()
8686
def lint(session):
87-
session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
87+
# Check that importing the client still works without optional dependencies
88+
session.install(".", env=INSTALL_ENV)
89+
session.run("python", "-c", "from elasticsearch import Elasticsearch")
90+
session.run("python", "-c", "from elasticsearch._otel import OpenTelemetry")
8891

92+
session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
8993
session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
9094
session.run("black", "--check", *SOURCE_FILES)
9195
session.run("flake8", *SOURCE_FILES)
9296
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)
9397

94-
# Workaround to make '-r' to still work despite uninstalling aiohttp below.
9598
session.install(".[async,requests,orjson]", env=INSTALL_ENV)
9699

97100
# Run mypy on the package and then the type examples separately for

0 commit comments

Comments
 (0)