@@ -60,18 +60,18 @@ def q_str(part: Union[str, int, None]) -> str:
6060 if isinstance (part , int ):
6161 return str (part )
6262 return "'%s'" % part # pylint: disable=consider-using-f-string
63- def sh____ (cmd : Union [str , List [str ]], shell : bool = True ) -> int :
63+ def sh____ (cmd : Union [str , List [str ]], shell : bool = True , env = None ) -> int :
6464 if isinstance (cmd , string_types ):
6565 logg .info (": %s" , cmd )
6666 else :
6767 logg .info (": %s" , " " .join ([q_str (item ) for item in cmd ]))
68- return subprocess .check_call (cmd , shell = shell )
69- def sx____ (cmd : Union [str , List [str ]], shell : bool = True ) -> int :
68+ return subprocess .check_call (cmd , shell = shell , env = env )
69+ def sx____ (cmd : Union [str , List [str ]], shell : bool = True , env = None ) -> int :
7070 if isinstance (cmd , string_types ):
7171 logg .info (": %s" , cmd )
7272 else :
7373 logg .info (": %s" , " " .join ([q_str (item ) for item in cmd ]))
74- return subprocess .call (cmd , shell = shell )
74+ return subprocess .call (cmd , shell = shell , env = env )
7575
7676class CalledProcessError (subprocess .SubprocessError ):
7777 def __init__ (self , args : Union [str , List [str ]], returncode : int = 0 , stdout : Union [str ,bytes ] = NIX , stderr : Union [str ,bytes ] = NIX ) -> None :
@@ -889,6 +889,36 @@ class X(TypedDict):
889889 self .assertEqual (x2 .out , "Success: no issues found in 1 source file" )
890890 self .rm_testdir ()
891891 self .end ()
892+ def test_3541 (self ) -> None :
893+ """ check Enum classes are replaced by local def"""
894+ vv = self .begin ()
895+ python = PYTHON
896+ tmp = self .testdir ()
897+ text_file (F"{ tmp } /test3.py" , """
898+ from enum import Enum
899+ class A(Enum):
900+ B = 2
901+ C = 3
902+ def func1() -> A:
903+ return A(3)
904+ f = func1()
905+ if f is A.C:
906+ print("OK:", f)
907+ else:
908+ print("NO:", f)
909+ """ )
910+ sh____ (F"{ PYTHON3 } { STRIP } -3 { tmp } /test3.py { vv } " , env = {"PYTHON3_ENUM_CLASS_ATLEAST" :"3.99" })
911+ self .assertTrue (os .path .exists (F"{ tmp } /test.py" ))
912+ self .assertTrue (os .path .exists (F"{ tmp } /test.pyi" ))
913+ script = lines4 (open (F"{ tmp } /test.py" ).read ())
914+ logg .info ("script = %s" , script )
915+ self .assertTrue (greps (script , "(3, 99)" ))
916+ self .assertTrue (greps (script , "class Enum" ))
917+ x1 = X (F"{ python } { tmp } /test.py" )
918+ logg .info ("%s -> %s\n %s" , x1 .args , x1 .out , x1 .err )
919+ self .assertTrue (greps (x1 .out , "OK: <C: 3>" ))
920+ self .rm_testdir ()
921+ self .end ()
892922
893923
894924if __name__ == "__main__" :
0 commit comments