Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Address warnings / errors for locally created methods #2287

Open
1 of 4 tasks
JosuaCarl opened this issue Nov 28, 2024 · 2 comments
Open
1 of 4 tasks

[Refactor] Address warnings / errors for locally created methods #2287

JosuaCarl opened this issue Nov 28, 2024 · 2 comments
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon 🔒 Staff only Can only be assigned to the Taipy R&D team

Comments

@JosuaCarl
Copy link
Contributor

JosuaCarl commented Nov 28, 2024

Description

When I try to use code with method creation within methods, the warning

WARNING:root:
--- 1 warning(s) were found for page '/' in variable '_' ---

  • Warning 1: button.on_action: print_something is not a function.

/.../lib/python3.12/site-packages/taipy/gui/gui.py:1502: TaipyGuiWarning: on_action(): 'print_something' is not a valid function.
_warn(f"on_action(): '{action}' is not a valid function.")

is raised.

Example:

in_str = "things!"
out_str = ""
def create_x( name:str ):
    def print_something( state, *args, something:str=name ):
        state.out_str =  f"{something} {state.in_str}"
    tgb.input( "{in_str}" )
    tgb.button( "Printer of something", on_action=print_something )
    tgb.text( "{out_str}" )

with tgb.Page() as root:
    create_x( name="Awsome" )

gui = Gui(page=root)

if __name__ == "__main__":
    gui.run(port=4999)

What does however work is, if I replace the function with a lamba statement, like:

tgb.button( "Printer of something", on_action=lambda state, id, payload: print_something( state ) )

The workaround is absolutely sufficient, but I am curious whether this could be addressed in a future release and why the lambda statement does not produce any error.

Acceptance Criteria

  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@JosuaCarl JosuaCarl added the 📈 Improvement Improvement of a feature. label Nov 28, 2024
@JosuaCarl JosuaCarl changed the title [Refactor] No warnings / errors for locally created methods [Refactor] Address warnings / errors for locally created methods Nov 28, 2024
@FlorianJacta FlorianJacta added 🟧 Priority: High Must be addressed as soon 🖰 GUI Related to GUI labels Nov 28, 2024
@FlorianJacta FlorianJacta added 💥Malfunction Addresses an identified problem. and removed 📈 Improvement Improvement of a feature. labels Dec 6, 2024
@jrobinAV
Copy link
Member

@FlorianJacta Can you check that this will be fixed in 4.0.2?

@jrobinAV jrobinAV added the 🔒 Staff only Can only be assigned to the Taipy R&D team label Dec 16, 2024
@FlorianJacta
Copy link
Member

Sure, tell me when I can test this with 4.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon 🔒 Staff only Can only be assigned to the Taipy R&D team
Projects
None yet
Development

No branches or pull requests

3 participants