Skip to content

Commit

Permalink
deprecates casting for boolean static_analysis flag fixes #586
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Apr 18, 2022
1 parent 904cbc4 commit 962e2aa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
20 changes: 0 additions & 20 deletions src/ploomber/sources/notebooksource.py
Expand Up @@ -226,26 +226,6 @@ def __init__(self,
'Placeholder or pathlib.Path, got {}'.format(
type(primitive)))

if static_analysis is False:
warnings.warn(
"In Ploomber 0.16, static_analysis "
"changed from a boolean to a string. "
"Change the value from False"
f" to 'disable' in {str(self._path)!r} "
"to remove this warning. "
"This will raise an error in Ploomber 0.18", FutureWarning)
static_analysis = 'disable'

if static_analysis is True:
warnings.warn(
"In Ploomber 0.16, static_analysis "
"changed from a boolean to a string. "
"Change the value from True"
f" to 'regular' in {str(self._path)!r} "
"to remove this warning. "
"This will raise an error in Ploomber 0.18", FutureWarning)
static_analysis = 'regular'

static_analysis_vals = {'disable', 'regular', 'strict'}

if static_analysis not in static_analysis_vals:
Expand Down
11 changes: 3 additions & 8 deletions tests/sources/test_notebooksource.py
Expand Up @@ -282,9 +282,7 @@ def test_nb_str_contains_kernel_info():


def test_ignores_static_analysis_if_non_python_file():
source = NotebookSource(new_nb(fmt='r:light'),
ext_in='R',
static_analysis=True)
source = NotebookSource(new_nb(fmt='r:light'), ext_in='R')
params = Params._from_dict({'product': File('output.ipynb')})

source.render(params)
Expand All @@ -296,10 +294,7 @@ def test_no_error_if_missing_product_or_upstream():
# +
"""
source = NotebookSource(code,
ext_in='py',
kernelspec_name='python3',
static_analysis=True)
source = NotebookSource(code, ext_in='py', kernelspec_name='python3')

params = Params._from_dict({'product': File('output.ipynb')})

Expand All @@ -312,7 +307,7 @@ def test_static_analysis(hot_reload, tmp_directory):
path = Path('nb.ipynb')
path.write_text(jupytext.writes(nb, fmt='ipynb'))

source = NotebookSource(path, static_analysis=True, hot_reload=hot_reload)
source = NotebookSource(path, hot_reload=hot_reload)

params = Params._from_dict({
'product': File('output.ipynb'),
Expand Down
17 changes: 0 additions & 17 deletions tests/tasks/test_notebook.py
Expand Up @@ -859,23 +859,6 @@ def test_validates_static_analysis_value(tmp_sample_tasks):
assert expected == str(excinfo.value)


@pytest.mark.parametrize('value, replacement, message', [
[False, 'disable', "from False to 'disable'"],
[True, 'regular', "from True to 'regular'"],
])
def test_compatibility_with_static_analysis_bool(tmp_sample_tasks, value,
replacement, message):

with pytest.warns(FutureWarning) as records:
task = NotebookRunner(Path('sample.ipynb'),
File('out.ipynb'),
dag=DAG(),
static_analysis=value)

assert task.static_analysis == replacement
assert message in records[0].message.args[0]


def test_warns_on_unused_parameters(tmp_sample_tasks):
dag = DAG()
NotebookRunner(Path('sample.ipynb'),
Expand Down

0 comments on commit 962e2aa

Please sign in to comment.