mirror of
https://github.com/pyscript/pyscript.git
synced 2026-04-30 16:00:32 -04:00
Deprecate pyscript output attribute (#981)
* Deprecate pyscript output attribute * Update pyscriptjs/src/components/pyscript.ts Co-authored-by: Antonio Cuni <anto.cuni@gmail.com> Co-authored-by: Antonio Cuni <anto.cuni@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { htmlDecode, ensureUniqueId } from '../utils';
|
||||
import { htmlDecode, ensureUniqueId, showWarning } from '../utils';
|
||||
import type { Runtime } from '../runtime';
|
||||
import { getLogger } from '../logger';
|
||||
import { pyExec } from '../pyexec';
|
||||
@@ -10,6 +10,14 @@ const logger = getLogger('py-script');
|
||||
export function make_PyScript(runtime: Runtime) {
|
||||
class PyScript extends HTMLElement {
|
||||
async connectedCallback() {
|
||||
if (this.hasAttribute('output')) {
|
||||
const deprecationMessage = (
|
||||
"The 'output' attribute is deprecated and ignored. You should use " +
|
||||
"'display()' to output the content to a specific element. " +
|
||||
'For example display(myElement, target="divID").'
|
||||
)
|
||||
showWarning(deprecationMessage)
|
||||
}
|
||||
ensureUniqueId(this);
|
||||
const pySrc = await this.getPySrc();
|
||||
this.innerHTML = '';
|
||||
|
||||
@@ -34,6 +34,18 @@ class TestOutput(PyScriptTest):
|
||||
lines = [line for line in lines if line != ""] # remove empty lines
|
||||
assert lines == ["hello 1", "hello 2", "hello 3"]
|
||||
|
||||
def test_output_attribute_shows_deprecated_warning(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script output="myDiv">
|
||||
display('hello world')
|
||||
</py-script>
|
||||
<div id="mydiv"></div>
|
||||
"""
|
||||
)
|
||||
warning_banner = self.page.locator(".alert-banner")
|
||||
assert "The 'output' attribute is deprecated" in warning_banner.inner_text()
|
||||
|
||||
def test_target_attribute(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user