File tree Expand file tree Collapse file tree 1 file changed +28
-16
lines changed
pybind11_stubgen/parser/mixins Expand file tree Collapse file tree 1 file changed +28
-16
lines changed Original file line number Diff line number Diff line change @@ -512,22 +512,28 @@ class FixNumpyArrayDimAnnotation(IParser):
512512 __annotated_name = QualifiedName .from_str ("Annotated" )
513513 numpy_primitive_types : set [QualifiedName ] = set (
514514 map (
515- lambda name : QualifiedName .from_str ( f"numpy. { name } " ) ,
515+ QualifiedName .from_str ,
516516 (
517- "uint8" ,
518- "int8" ,
519- "uint16" ,
520- "int16" ,
521- "uint32" ,
522- "int32" ,
523- "uint64" ,
524- "int64" ,
525- "float16" ,
526- "float32" ,
527- "float64" ,
528- "complex32" ,
529- "complex64" ,
530- "longcomplex" ,
517+ "bool" ,
518+ * map (
519+ lambda name : f"numpy.{ name } " ,
520+ (
521+ "uint8" ,
522+ "int8" ,
523+ "uint16" ,
524+ "int16" ,
525+ "uint32" ,
526+ "int32" ,
527+ "uint64" ,
528+ "int64" ,
529+ "float16" ,
530+ "float32" ,
531+ "float64" ,
532+ "complex32" ,
533+ "complex64" ,
534+ "longcomplex" ,
535+ ),
536+ ),
531537 ),
532538 )
533539 )
@@ -696,9 +702,15 @@ def parse_annotation_str(
696702 ):
697703 return result
698704
705+ name = scalar_with_dims .name
706+ # Pybind annotates a bool Python type, which cannot be used with
707+ # numpy.dtype because it does not inherit from numpy.generic.
708+ # Only numpy.bool_ works reliably with both NumPy 1.x and 2.x.
709+ if str (name ) == "bool" :
710+ name = QualifiedName .from_str ("numpy.bool_" )
699711 dtype = ResolvedType (
700712 name = QualifiedName .from_str ("numpy.dtype" ),
701- parameters = [ResolvedType (name = scalar_with_dims . name )],
713+ parameters = [ResolvedType (name = name )],
702714 )
703715
704716 shape = self .parse_annotation_str ("Any" )
You can’t perform that action at this time.
0 commit comments