Skip to content

Commit 2dec7c9

Browse files
committed
revert: keep dynamic imports for asgi module to avoid loading for Flask apps
Reverts the direct import of StarletteApplication to keep it as a dynamic import. This ensures that Flask-only users don't load the asgi module and its starlette/uvicorn dependencies unnecessarily.
1 parent 43d773e commit 2dec7c9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/functions_framework/_http/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from flask import Flask
1616

17-
from functions_framework._http.asgi import StarletteApplication
1817
from functions_framework._http.flask import FlaskApplication
1918

2019

@@ -36,13 +35,17 @@ def __init__(self, app, debug, **options):
3635
self.server_class = FlaskApplication
3736
else: # pragma: no cover
3837
if self.debug:
38+
from functions_framework._http.asgi import StarletteApplication
39+
3940
self.server_class = StarletteApplication
4041
else:
4142
try:
4243
from functions_framework._http.gunicorn import UvicornApplication
4344

4445
self.server_class = UvicornApplication
4546
except ImportError as e:
47+
from functions_framework._http.asgi import StarletteApplication
48+
4649
self.server_class = StarletteApplication
4750

4851
def run(self, host, port):

tests/test_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def test_httpserver_asgi(monkeypatch, debug, uvicorn_missing, expected):
154154
}
155155
options = {"a": pretend.stub(), "b": pretend.stub()}
156156

157-
import functions_framework._http
157+
from functions_framework._http import asgi
158158

159-
monkeypatch.setattr(functions_framework._http, "StarletteApplication", server_classes["starlette"])
159+
monkeypatch.setattr(asgi, "StarletteApplication", server_classes["starlette"])
160160

161161
if uvicorn_missing or platform.system() == "Windows":
162162
monkeypatch.setitem(sys.modules, "functions_framework._http.gunicorn", None)

0 commit comments

Comments
 (0)