diff options
| -rw-r--r-- | python/__init__.py | 1 | ||||
| -rw-r--r-- | python/deprecation.py | 19 | ||||
| -rw-r--r-- | python/function.py | 7 |
3 files changed, 23 insertions, 4 deletions
diff --git a/python/__init__.py b/python/__init__.py index 913fde6a..697dfff8 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -27,6 +27,7 @@ from typing import Mapping, Optional # Binary Ninja components import binaryninja._binaryninjacore as core +__version__ = core.BNGetVersionString() import binaryninja from .enums import * from .databuffer import * 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. diff --git a/python/function.py b/python/function.py index 856d9cca..86662cf7 100644 --- a/python/function.py +++ b/python/function.py @@ -45,6 +45,7 @@ from . import flowgraph from . import callingconvention from . import workflow from . import deprecation +from . import __version__ # we define the following as such so the linter doesn't confuse 'highlight' the module with the # property of the same name. There is probably some other work around but it eludes me. @@ -960,9 +961,8 @@ class Function: return None return highlevelil.HighLevelILFunction(self.arch, result, self) - # TODO: Uncomment, move below the property decorator, and mark deprecated after the next stable - #@deprecation.deprecated(details="Use .type instead.") @property + @deprecation.deprecated(details="Use .type instead", deprecated_in="3.4", current_version=__version__) def function_type(self) -> 'types.FunctionType': """ Function type object, can be set with either a string representing the function prototype @@ -970,9 +970,8 @@ class Function: """ return self.type - # TODO: Uncomment, move below the setter decorator, and mark deprecated after the next stable - #@deprecation.deprecated(details="Use .type instead.") @function_type.setter + @deprecation.deprecated(details="Use .type instead", deprecated_in="3.4", current_version=__version__) def function_type(self, value: Union['types.FunctionType', str]) -> None: self.type = value |
