Skip to content

Commit

Permalink
rename notfound_ok as check_exists with a default of True
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt committed Jul 27, 2023
1 parent 76629aa commit 0b1825b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions param/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2324,28 +2324,28 @@ class Path(Parameter):
is None).
"""

__slots__ = ['search_paths', 'notfound_ok']
__slots__ = ['search_paths', 'check_exists']

_slot_defaults = _dict_update(
Parameter._slot_defaults, notfound_ok=False,
Parameter._slot_defaults, check_exists=True,
)

@typing.overload
def __init__(
self,
default=None, *, search_paths=None, notfound_ok=False,
default=None, *, search_paths=None, check_exists=True,
allow_None=False, doc=None, label=None, precedence=None, instantiate=False,
constant=False, readonly=False, pickle_default_value=True, per_instance=True
):
...

@_deprecate_positional_args
def __init__(self, default=Undefined, *, search_paths=Undefined, notfound_ok=Undefined, **params):
def __init__(self, default=Undefined, *, search_paths=Undefined, check_exists=Undefined, **params):
if search_paths is Undefined:
search_paths = []

self.search_paths = search_paths
self.notfound_ok = notfound_ok
self.check_exists = check_exists
super().__init__(default,**params)
self._validate(self.default)

Expand All @@ -2360,7 +2360,7 @@ def _validate(self, val):
try:
self._resolve(val)
except OSError as e:
if not self.notfound_ok:
if self.check_exists:
raise OSError(e.args[0]) from None

def __get__(self, obj, objtype):
Expand All @@ -2374,7 +2374,7 @@ def __get__(self, obj, objtype):
try:
path = self._resolve(raw_path)
except OSError:
if not self.notfound_ok:
if self.check_exists:
raise
else:
path = raw_path
Expand Down
18 changes: 9 additions & 9 deletions tests/testpathparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class P(param.Parameterized):
a = param.Path()
b = param.Path(self.fb)
c = param.Path('a.txt', search_paths=[tmpdir1])
d = param.Path(notfound_ok=True)
d = param.Path(check_exists=False)

self.P = P

Expand All @@ -40,7 +40,7 @@ def _check_defaults(self, p):
assert p.default is None
assert p.allow_None is True
assert p.search_paths == []
assert p.notfound_ok is False
assert p.check_exists is True

def test_defaults_class(self):
class P(param.Parameterized):
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_set_notfound_class_raises_error(self):
self.P.a = 'non/existing/file'

def test_notfoundok_unbound_no_error(self):
p = param.Path('non/existing/file', notfound_ok=True)
p = param.Path('non/existing/file', check_exists=False)
assert p.default == 'non/existing/file'

def test_notfoundok_class_no_error(self):
Expand Down Expand Up @@ -181,7 +181,7 @@ class P(param.Parameterized):
a = param.Filename()
b = param.Filename(self.fb)
c = param.Filename('a.txt', search_paths=[tmpdir1])
d = param.Filename(notfound_ok=True)
d = param.Filename(check_exists=False)

self.P = P

Expand All @@ -192,7 +192,7 @@ def _check_defaults(self, p):
assert p.default is None
assert p.allow_None is True
assert p.search_paths == []
assert p.notfound_ok is False
assert p.check_exists is True

def test_defaults_class(self):
class P(param.Parameterized):
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_set_notfound_raises_error(self):
p.a = 'non/existing/file'

def test_notfoundok_unbound_no_error(self):
p = param.Filename('non/existing/file', notfound_ok=True)
p = param.Filename('non/existing/file', check_exists=False)
assert p.default == 'non/existing/file'

def test_notfoundok_class_no_error(self):
Expand Down Expand Up @@ -301,7 +301,7 @@ class P(param.Parameterized):
a = param.Foldername()
b = param.Foldername(tmpdir1)
c = param.Foldername('da', search_paths=[tmpdir1])
d = param.Foldername(notfound_ok=True)
d = param.Foldername(check_exists=False)

self.P = P

Expand All @@ -312,7 +312,7 @@ def _check_defaults(self, p):
assert p.default is None
assert p.allow_None is True
assert p.search_paths == []
assert p.notfound_ok is False
assert p.check_exists is True

def test_defaults_class(self):
class P(param.Parameterized):
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_set_notfound_class_raises_error(self):
self.P.a = 'non/existing/folder'

def test_notfoundok_unbound_no_error(self):
p = param.Foldername('non/existing/folder', notfound_ok=True)
p = param.Foldername('non/existing/folder', check_exists=False)
assert p.default == 'non/existing/folder'

def test_notfoundok_class_no_error(self):
Expand Down

0 comments on commit 0b1825b

Please sign in to comment.