Skip to content

Commit

Permalink
Fix .abstract for classes named with leading underscore(s) (#439)
Browse files Browse the repository at this point in the history
* Fix abstract class check for classes with leading underscore(s) in name (previously an declared abstract _Class would come back as not abstract).

* Add note about API0 and API1 test suites.
  • Loading branch information
ceball committed Oct 22, 2020
1 parent f68fffc commit adb0641
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions param/parameterized.py
Expand Up @@ -2087,9 +2087,9 @@ def __is_abstract(mcs):
# _ParameterizedMetaclass__abstract before running, but
# the actual class object will have an attribute
# _ClassName__abstract. So, we have to mangle it ourselves at
# runtime.
# runtime. Mangling follows description in https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references
try:
return getattr(mcs,'_%s__abstract'%mcs.__name__)
return getattr(mcs,'_%s__abstract'%mcs.__name__.lstrip("_"))
except AttributeError:
return False

Expand Down
5 changes: 5 additions & 0 deletions tests/API0/testparameterizedobject.py
Expand Up @@ -39,6 +39,10 @@ class AnotherTestPO(param.Parameterized):
class TestAbstractPO(param.Parameterized):
__abstract = True

class _AnotherAbstractPO(param.Parameterized):
__abstract = True


@nottest
class TestParamInstantiation(AnotherTestPO):
instPO = param.Parameter(default=AnotherTestPO(),instantiate=False)
Expand Down Expand Up @@ -118,6 +122,7 @@ def test_instantiation_inheritance(self):
def test_abstract_class(self):
"""Check that a class declared abstract actually shows up as abstract."""
self.assertEqual(TestAbstractPO.abstract,True)
self.assertEqual(_AnotherAbstractPO.abstract,True)
self.assertEqual(TestPO.abstract,False)


Expand Down
4 changes: 4 additions & 0 deletions tests/API1/testparameterizedobject.py
Expand Up @@ -53,6 +53,9 @@ class AnotherTestPO(param.Parameterized):
class TestAbstractPO(param.Parameterized):
__abstract = True

class _AnotherAbstractPO(param.Parameterized):
__abstract = True

@nottest
class TestParamInstantiation(AnotherTestPO):
instPO = param.Parameter(default=AnotherTestPO(),instantiate=False)
Expand Down Expand Up @@ -140,6 +143,7 @@ def test_instantiation_inheritance(self):
def test_abstract_class(self):
"""Check that a class declared abstract actually shows up as abstract."""
self.assertEqual(TestAbstractPO.abstract,True)
self.assertEqual(_AnotherAbstractPO.abstract,True)
self.assertEqual(TestPO.abstract,False)


Expand Down
13 changes: 13 additions & 0 deletions tests/README.md
@@ -0,0 +1,13 @@
In 2018, we moved most of `Parameterized` onto a `param` namespace
object, expecting this to be the public API of param 2.0, and cleaning
up the namespace of user classes.

The new API has been in use for a while within holoviz projects, but
we're still changing it. Meanwhile, the previous API remains
available.

The original API's tests were copied into an `API0` subdirectory,
while tests in `API1` use the new API.

(Probably not ideal to just copy everything, and cleaning up would be
great, but this explains the two directories you see here.)

0 comments on commit adb0641

Please sign in to comment.