question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Pass custom parameters to `App`

See original GitHub issue

(I know textual is still in active development and that this might be in the works, but just throwing it up here to help keep track)

There’s no way to pass in and store values inside a class that inherits from App, to store application-level information. For instance, the following code does not work:

class MyApp(App):
    def __init__(self, custom_arg, *args, **kwargs):
        self.custom_arg = custom_arg
        super().__init__(*args, **kwargs)
    async def on_mount(self):
        print(self.custom_arg)
MyApp(5).run()

The cause of this seems the be that in the run() function, a new instance of MyApp is created, which is the instance on which on_mount() is actually caused. This is a bit annoying and requires using global variables to store the parameters we want, which is not ideal.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

6reactions
CyberSmashcommented, Oct 12, 2021

Because I came looking for this, The above code is slightly wrong. More correct is:

class MyApp(App):
    def __init__(self, *args, custom_arg, **kwargs):
        self.custom_arg = custom_arg
        super().__init__(*args, **kwargs)
    async def on_mount(self):
        print(self.custom_arg)
# This is the change, no () after MyApp
MyApp.run(custom_arg=5)
0reactions
github-actions[bot]commented, Oct 25, 2022

Did we solve your problem?

Consider buying the Textualize developers a coffee to say thanks.

Textualize

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create custom parameters for advanced tracking - Google Help
Custom parameters are an advanced type of URL parameter that you can add to your ad's landing page URLs. Unlike ValueTrack parameters, you...
Read more >
Passing custom parameters to pre-registration action from ...
Yes! This is possible. The custom parameters you pass to the /authorize request can be retrieved in the event.request property in the Pre ......
Read more >
Is there a way to pass a custom parameter when make a call ...
Finally, I received a response from Twilio Support: Unfortunately you cannot add custom parameters such as below.
Read more >
How to pass custom parameter in cart checkout into request?
Solved: Hi everybody, I want to pass an own ID while checking out my cart. That ID should be saved in my request...
Read more >
Feature requests - Passbase
Add Feature Request ... Add feature to allow custom document uploads. ... of default tab in the Passbase dashboard or through a parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found