Skip to content

Commit

Permalink
Fixes to better report issue with class definitions not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgautier committed Feb 24, 2024
1 parent 13e9c43 commit 92dcd14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Changes
Python default handler (instead of a custom handler raising
:class:`KeyboardInterrupt`).

Bugs fixed
----------

- :meth:`rpy2.robjects.methods.getclassdef` was not reporting
clearly errors due unspecified package name or missing class
definition in within the package namespace specified.


Release 3.5.15
==============
Expand Down
11 changes: 10 additions & 1 deletion rpy2/robjects/methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
from types import SimpleNamespace
import warnings
from rpy2.robjects.robject import RObjectMixin
import rpy2.rinterface as rinterface
from rpy2.rinterface import StrSexpVector
Expand Down Expand Up @@ -87,10 +88,18 @@ def classname(self):


def getclassdef(cls_name: str, packagename=rinterface.MissingArg):
if packagename is None:
package = rinterface.MissingArg
else:
package = StrSexpVector((packagename, ))
cls_def = methods_env['getClassDef'](
StrSexpVector((cls_name,)),
package=StrSexpVector((packagename, ))
package=package
)
if cls_def is rinterface.NULL:
raise ValueError(
f'{cls_name} is not a class in the R package {packagename!r}'
)
cls_def = ClassRepresentation(cls_def)
cls_def.__rname__ = cls_name
return cls_def
Expand Down

0 comments on commit 92dcd14

Please sign in to comment.