Skip to content

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

@morrison12

Description

@morrison12

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:

class FactBase(Generic[T]):
name: str
abstract: bool = True
shell_executable: str | None = None
command: Callable[..., str | StringCommand]

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions