pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Typing Question on FactBase.command in 3.x (3.4.1 at the moment)

Open morrison12 opened this issue 4 months ago • 0 comments

If I understand correctly, the current typing prohibits static strings as FactBase.commands as command is typed as a Callable returning either a str or StringCommand: https://github.com/pyinfra-dev/pyinfra/blob/cc58a74e561d9b6699724f0fe770783796938db5/pyinfra/api/facts.py#L50-L59

I had naively expected str to be allowed [1] as a type for command given it works today; should I assume the typing means that support of static strings will be phased out and in newly written facts something like following should be used ?

   @staticmethod
   def command() -> str:
       return "<some useful command>"

[1] To force fact authors to provide a value, this would admittedly require though the signature to allow both str and None and __init_subclass__ to raise an exception on None values. StringCommand could be included as well if wanted.

morrison12 avatar Sep 01 '25 20:09 morrison12