File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,12 @@ def _get_sequence(
106106    """Get a list value from the dictionary and verify it's the expected items type.""" 
107107    if  (value  :=  _get (d , Sequence , key )) is  None :  # type: ignore[type-abstract] 
108108        return  None 
109+     if  isinstance (value , str ):
110+         # special case: str is a Sequence, but we want to reject it 
111+         raise  PylockValidationError (
112+             f"Unexpected type { type (value ).__name__ }   (expected Sequence)" ,
113+             context = key ,
114+         )
109115    for  i , item  in  enumerate (value ):
110116        if  not  isinstance (item , expected_item_type ):
111117            raise  PylockValidationError (
Original file line number Diff line number Diff line change @@ -508,3 +508,17 @@ def test_validate() -> None:
508508        str (exc_info .value )
509509        ==  "Name 'example_package' is not normalized in 'packages[0].name'" 
510510    )
511+ 
512+ 
513+ def  test_validate_sequence_of_str () ->  None :
514+     pylock  =  Pylock (
515+         lock_version = Version ("1.0" ),
516+         created_by = "some_tool" ,
517+         packages = [],
518+         dependency_groups = "abc" ,  # should be a sequence of str 
519+     )
520+     with  pytest .raises (PylockValidationError ) as  exc_info :
521+         pylock .validate ()
522+     assert  str (exc_info .value ) ==  (
523+         "Unexpected type str (expected Sequence) in 'dependency-groups'" 
524+     )
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments