8000 Fix type hints _PassWorkingDb by rdesparbes · Pull Request #301 · CEXT-Dan/PyRx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix type hints _PassWorkingDb #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/pytest-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ jobs:
pip install -e .[dev]

- name: Run Pytest
run: pytest
run: |
TEST_PATHS=(
# tests/test_ap
# tests/test_commands
# tests/test_core
# tests/test_db
tests/test_doc_utils/test_misc.py
tests/test_doc_utils/test_parse_docstring.py
# tests/test_doc_utils/test_pyi_gen.py
# tests/test_utils
# tests/test_console.py
)
pytest "${TEST_PATHS[@]}"
13 changes: 1 addition & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,7 @@ Repository = "https://github.com/CEXT-Dan/PyRx"
Issues = "https://github.com/CEXT-Dan/PyRx/issues"

[tool.pytest.ini_options]
testpaths = [
# "tests/test_ap",
# "tests/test_commands",
# "tests/test_core",
# "tests/test_db",
"tests/test_doc_utils/test_misc.py",
"tests/test_doc_utils/test_parse_docstring.py",
# "tests/test_doc_utils/test_pyi_gen.py",
# "tests/test_utils",
# "tests/test_console.py"
]

testpaths = ["tests"]

[tool.ruff]
line-length = 99
Expand Down
11 changes: 6 additions & 5 deletions pyrx/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from pyrx import Db

_EMPTY = object()
T = t.TypeVar("T")
_P = t.ParamSpec("_P")
_R = t.TypeVar("_R")


class _PassWorkingDb(t.Generic[T]):
def __init__(self, func: t.Callable[..., T]):
class _PassWorkingDb(t.Generic[_P, _R]):
def __init__(self, func: t.Callable[_P, _R]):
self.sig = inspect.signature(func)
try:
db_param = self.sig.parameters["db"]
Expand All @@ -25,7 +26,7 @@ def __init__(self, func: t.Callable[..., T]):
raise RuntimeError("Function 'db' parameter must be positional or keyword")
self.func = func

def __call__(self, *args, **kwargs) -> T:
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
# fix the parameters to include the working database
args, kwargs = self.fix_params(args, kwargs)

Expand Down Expand Up @@ -61,7 +62,7 @@ def get_db(self) -> Db.Database:
return Db.workingDb()


def pass_working_db(func: t.Callable[..., T]) -> t.Callable[..., T]:
def pass_working_db(func: t.Callable[_P, _R]) -> t.Callable[_P, _R]:
"""
Decorator to ensure the working database is passed to the function.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class AbstractViewTableRecord(PyDb.SymbolTableRecord):
# (...) #
def __init__(self, id: PyDb.ObjectId, mode: PyDb.OpenMode = PyDb.OpenMode.kForRead, /) -> None: ...
def __init__(self, id: PyDb.ObjectId, mode: PyDb.OpenMode = PyDb.OpenMode.kForRead, /) -> None:
"""
This class is the base class for the AcDbViewTableRecord and AcDbViewportTableRecord
classes.
"""
# (...) #
def __reduce__(self, /) -> Any: ...
# (...) #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ from pyrx.doc_utils.boost_meta import _BoostPythonEnum
kForReadAndAllShare: DatabaseOpenMode # 3
# (...) #
class AbstractViewTableRecord(PyDb.SymbolTableRecord):
def __init__(self, id: PyDb.ObjectId, mode: PyDb.OpenMode = PyDb.OpenMode.kForRead, /) -> None: ...
def __init__(self, id: PyDb.ObjectId, mode: PyDb.OpenMode = PyDb.OpenMode.kForRead, /) -> None:
"""
This class is the base class for the AcDbViewTableRecord and AcDbViewportTableRecord
classes.
"""
# (...) #
def __reduce__(self, /) -> Any: ...
# (...) #
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_db_as_keyword_argument(self):
mock_db = object()

@pass_working_db
def func(*, other, db):
def func(*, other, db = ...):
return other, db

with patch("pyrx.Db.workingDb", return_value=mock_db):
Expand Down
0