deprecate __version__ attribute

This commit is contained in:
David Lord 2023-08-29 06:03:11 -07:00
parent 153433f612
commit 293041a290
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 23 additions and 2 deletions

View file

@ -1,3 +1,7 @@
from __future__ import annotations
import typing as t
from . import json as json
from .app import Flask as Flask
from .blueprints import Blueprint as Blueprint
@ -38,4 +42,19 @@ from .templating import stream_template_string as stream_template_string
from .wrappers import Request as Request
from .wrappers import Response as Response
__version__ = "3.0.0.dev"
def __getattr__(name: str) -> t.Any:
if name == "__version__":
import importlib.metadata
import warnings
warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" Flask 3.1. Use feature detection or"
" 'importlib.metadata.version(\"flask\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("flask")
raise AttributeError(name)