Skip to content

Commit

Permalink
Merge pull request #41 from ionite34/patch-funcview-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ionite34 committed Jan 27, 2023
2 parents 215532f + c5812a7 commit 45165ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
build:
name: Docs Check
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions:

jobs:
build:
name: Docs Deploy
runs-on: ubuntu-latest

steps:
Expand Down
10 changes: 5 additions & 5 deletions src/einspect/views/view_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ def vectorcall(self, value: Callable) -> None:
self._pyobject.vectorcall = vectorcallfunc(value)

@property
def func_version(self) -> int:
def version(self) -> int:
if Version.PY_3_11.below():
raise AttributeError(
"PyFunctionObject does not have func_version below Python 3.11"
"PyFunctionObject does not have version below Python 3.11"
)
return self._pyobject.func_version

@func_version.setter
@version.setter
@unsafe
def func_version(self, value: int) -> None:
def version(self, value: int) -> None:
if Version.PY_3_11.below():
raise AttributeError(
"PyFunctionObject does not have func_version below Python 3.11"
"PyFunctionObject does not have version below Python 3.11"
)
self._pyobject.func_version = value
19 changes: 19 additions & 0 deletions tests/views/test_view_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
from types import FunctionType
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -47,6 +48,24 @@ def test_builtins(self):
v = self.view_type(obj)
assert v.builtins == obj.__globals__["__builtins__"]

@pytest.mark.skipif(sys.version_info < (3, 11), reason="Python 3.11+ only")
def test_version(self):
obj = self.get_obj()
v = self.view_type(obj)
assert v.version == v._pyobject.func_version
with v.unsafe():
v.version = v._pyobject.func_version

@patch("einspect.compat.sys.version_info", (3, 10))
def test_version_error(self):
"""FunctionView.version should raise AttributeError on Python < 3.11"""
obj = self.get_obj()
v = self.view_type(obj)
with pytest.raises(AttributeError):
_ = v.version
with pytest.raises(AttributeError), v.unsafe():
v.version = 0

def test_globals(self):
# noinspection PyUnresolvedReferences
def foo():
Expand Down

0 comments on commit 45165ea

Please sign in to comment.