-
DescriptionHow do you pass instance methods to process commands from typer, it appears to choke on ? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
Could you provide some minimal example? |
Beta Was this translation helpful? Give feedback.
-
#!/bin/env python3
if True:
import typer
if __name__ == "__main__":
typer = typer.Typer()
class App():
def __init__(self):
global typer
self._typer = typer
self._x = self._y = self._z = 0.0
def __str__(self):
ostr = f"({self._x:.2f}, {self._y:.2f}, {self._z:.2f})"
return ostr
@typer.command()
def x(self, x: float):
self._x = x
self._typer.echo(self)
@typer.command()
def y(self, y: float):
self._y = y
self._typer.echo(self)
@typer.command()
def z(self, z: float):
self._z = z
self._typer.echo(self)
def run(self):
self._typer()
app = App()
app.run() |
Beta Was this translation helpful? Give feedback.
-
|
I created a repo that has some examples where typer is ussed inside classes: https://github.com/captainCapitalism/typer-oo-example . It was an answer to Issue #261 In short using decorator will give you these errors, but using |
Beta Was this translation helpful? Give feedback.
-
|
Muchas Gracias, Extremely Helpful, Thanks again! |
Beta Was this translation helpful? Give feedback.
-
|
@captaincapitalism Wonderful little repo you set up here that's coming in extremely handy for me. I was mostly just using it as a reference, but with a recent revision I may end up mirroring your setup almost exactly. Did you ever figure out the exact issue with the decorators? I wanted to use them in a class-based setup to avoid manually registering the commands in init if possible. Would be slightly cleaner. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the discussion! Class based apps are not supported. If anyone that comes here has a specific use case that would benefit from that, it would be great if you create a new discussion question, with the specific use case you need to solve that would need classes involved. ☕ |
Beta Was this translation helpful? Give feedback.
Thanks for the discussion!
Class based apps are not supported. If anyone that comes here has a specific use case that would benefit from that, it would be great if you create a new discussion question, with the specific use case you need to solve that would need classes involved. ☕