@@ -736,10 +736,11 @@ class command(FieldType):
736736 executable : path | None = None
737737 args : list [str ] | None = None
738738
739+ _raw : str | None = None
739740 _path_type : type [path ] = None
740- _posix : bool
741+ _posix : bool = True
741742
742- def __new__ (cls , value : str ):
743+ def __new__ (cls , value : str | None ):
743744 if cls is not command :
744745 return super ().__new__ (cls )
745746
@@ -757,17 +758,12 @@ def __new__(cls, value: str):
757758 cls = windows_command if windows else posix_command
758759 return super ().__new__ (cls )
759760
760- def __init__ (self , value : str | tuple [ str , tuple [ str ]] | None ):
761+ def __init__ (self , value : str | None ):
761762 if value is None :
762763 return
763764
764- if isinstance (value , str ):
765- self .executable , self .args = self ._split (value )
766- return
767-
768- executable , self .args = value
769- self .executable = self ._path_type (executable )
770- self .args = list (self .args )
765+ self ._raw = value
766+ self .executable , self .args = self ._split (self ._raw )
771767
772768 def __repr__ (self ) -> str :
773769 return f"(executable={ self .executable !r} , args={ self .args } )"
@@ -776,30 +772,29 @@ def __eq__(self, other: object) -> bool:
776772 if isinstance (other , command ):
777773 return self .executable == other .executable and self .args == other .args
778774 if isinstance (other , str ):
779- return self ._join () == other
775+ return self ._raw == other
780776 if isinstance (other , (tuple , list )):
781777 return self .executable == other [0 ] and self .args == list (other [1 :])
782778
783779 return False
784780
785- def _split (self , value : str ) -> tuple [str , list [str ]]:
781+ def _split (self , value : str ) -> tuple [path , list [str ]]:
786782 executable , * args = shlex .split (value , posix = self ._posix )
787783 executable = executable .strip ("'\" " )
788784
789785 return self ._path_type (executable ), args
790786
791787 def _join (self ) -> str :
792- return shlex . join ([ str ( self .executable ), * self . args ])
788+ return self ._raw
793789
794- def _pack (self ) -> tuple [tuple [ str , list ], str ]:
790+ def _pack (self ) -> tuple [str , int ]:
795791 command_type = TYPE_WINDOWS if isinstance (self , windows_command ) else TYPE_POSIX
796792 if self .executable :
797- _exec , _ = self .executable ._pack ()
798- return ((_exec , self .args ), command_type )
793+ return (self ._raw , command_type )
799794 return (None , command_type )
800795
801796 @classmethod
802- def _unpack (cls , data : tuple [tuple [ str , tuple ] | None , int ]) -> command :
797+ def _unpack (cls , data : tuple [str | None , int ]) -> command :
803798 _value , _type = data
804799 if _type == TYPE_WINDOWS :
805800 return windows_command (_value )
@@ -824,18 +819,8 @@ class windows_command(command):
824819 _posix = False
825820 _path_type = windows_path
826821
827- def _split (self , value : str ) -> tuple [str , list [str ]]:
828- executable , args = super ()._split (value )
829- if args :
830- args = [" " .join (args )]
822+ def _split (self , value : str ) -> tuple [path , list [str ]]:
823+ executable , _args = super ()._split (value )
824+ args = [" " .join (_args )] if _args else _args
831825
832826 return executable , args
833-
834- def _join (self ) -> str :
835- arg = f" { self .args [0 ]} " if self .args else ""
836- executable_str = str (self .executable )
837-
838- if " " in executable_str :
839- return f"'{ executable_str } '{ arg } "
840-
841- return f"{ executable_str } { arg } "
0 commit comments