diff options
| author | Josh Ferrell <josh@vector35.com> | 2023-02-13 14:27:59 -0500 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2023-02-13 14:27:59 -0500 |
| commit | 155b63c35683ded76398d3c97bc9db57790f4bbb (patch) | |
| tree | f9d2e22ffc7d75982d25d9c1b51eb2f2d0053509 /python/deprecation.py | |
| parent | 38fb1d656559cb4fb95201077d7aaf57d992a8c5 (diff) | |
Add __version__ attribute to python api, allow marking deprecation with future version marker
Diffstat (limited to 'python/deprecation.py')
| -rw-r--r-- | python/deprecation.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/deprecation.py b/python/deprecation.py index fecb3fbc..e6c5a482 100644 --- a/python/deprecation.py +++ b/python/deprecation.py @@ -9,6 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import re import collections import functools import textwrap @@ -30,6 +31,15 @@ __all__ = ["deprecated", "message_location", "fail_if_not_removed", message_location = "bottom" +# This is a patch applied to this library to allow specifying a deprecation version +def parse_version(version: str) -> tuple: + match = re.match(r"^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?", version) + if match is None: + return (0,0,0) + groups = match.groupdict() + return (int(groups['major']), int(groups['minor']), int(groups['patch'] or '0')) + + class DeprecatedWarning(DeprecationWarning): """A warning class for deprecated methods @@ -165,6 +175,15 @@ def deprecated(deprecated_in=None, removed_in=None, current_version=None, is_unsupported = True else: is_deprecated = True + elif current_version: + current_version = parse_version(current_version) + + if (removed_in + and current_version >= parse_version(removed_in)): + is_unsupported = True + elif (deprecated_in + and current_version >= parse_version(deprecated_in)): + is_deprecated = True else: # If we can't actually calculate that we're in a period of # deprecation...well, they used the decorator, so it's deprecated. |
