Skip to content

Commit 38c29ea

Browse files
committed
fix(core): set warning stacklevel and refine fallback version message
Add stacklevel=2 to FutureWarning calls in check_python_version and include the 'Python' prefix in min_python() so the fallback wording reads naturally.
1 parent 45a5e29 commit 38c29ea

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎firebase_admin/_python_version_support.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,20 @@ def min_python(date: datetime.date) -> str:
154154
"""Find the minimum supported Python version for a given date."""
155155
for version, info in sorted(PYTHON_VERSION_INFO.items()):
156156
if info.python_start <= date < info.python_eol:
157-
return f'{version[0]}.{version[1]}'
158-
return 'at a currently supported version [https://devguide.python.org/versions]'
157+
return f'Python {version[0]}.{version[1]}'
158+
return 'a currently supported Python version [https://devguide.python.org/versions]'
159159

160160
if end_of_support_date < today:
161161
message = _flatten_message(
162162
f"""
163163
You are using a non-supported Python version ({py_version_str}).
164164
Google will not post any further updates to {_PACKAGE_LABEL}
165165
supporting this Python version. Please upgrade to the latest Python
166-
version, or at least Python {min_python(today)}, and then update
166+
version, or at least {min_python(today)}, and then update
167167
{_PACKAGE_LABEL}.
168168
"""
169169
)
170-
warnings.warn(message, FutureWarning)
170+
warnings.warn(message, FutureWarning, stacklevel=2)
171171
return PythonVersionStatus.PYTHON_VERSION_UNSUPPORTED
172172

173173
if version_info.python_eol <= today <= end_of_support_date:
@@ -177,11 +177,11 @@ def min_python(date: datetime.date) -> str:
177177
past its end of life. Google will update {_PACKAGE_LABEL}
178178
with critical bug fixes on a best-effort basis, but not
179179
with any other fixes or features. Please upgrade
180-
to the latest Python version, or at least Python
180+
to the latest Python version, or at least
181181
{min_python(today)}, and then update {_PACKAGE_LABEL}.
182182
"""
183183
)
184-
warnings.warn(message, FutureWarning)
184+
warnings.warn(message, FutureWarning, stacklevel=2)
185185
return PythonVersionStatus.PYTHON_VERSION_EOL
186186

187187
if deprecation_date <= today < version_info.python_eol:
@@ -190,12 +190,12 @@ def min_python(date: datetime.date) -> str:
190190
You are using a Python version ({py_version_str}) which Google will
191191
stop supporting in new releases of {_PACKAGE_LABEL} once it reaches
192192
its end of life ({version_info.python_eol}). Please upgrade to the
193-
latest Python version, or at least Python
193+
latest Python version, or at least
194194
{min_python(version_info.python_eol)}, to continue receiving updates
195195
for {_PACKAGE_LABEL} past that date.
196196
"""
197197
)
198-
warnings.warn(message, FutureWarning)
198+
warnings.warn(message, FutureWarning, stacklevel=2)
199199
return PythonVersionStatus.PYTHON_VERSION_DEPRECATED
200200

201201
return PythonVersionStatus.PYTHON_VERSION_SUPPORTED

0 commit comments

Comments
 (0)