@@ -16,7 +16,9 @@ predicate is_unary_op(string name) {
1616 name in [
1717 "__del__" , "__repr__" , "__neg__" , "__pos__" , "__abs__" , "__invert__" , "__complex__" ,
1818 "__int__" , "__float__" , "__long__" , "__oct__" , "__hex__" , "__str__" , "__index__" , "__enter__" ,
19- "__hash__" , "__bool__" , "__nonzero__" , "__unicode__" , "__len__" , "__iter__" , "__reversed__"
19+ "__hash__" , "__bool__" , "__nonzero__" , "__unicode__" , "__len__" , "__iter__" , "__reversed__" ,
20+ "__aenter__" , "__aiter__" , "__anext__" , "__await__" , "__ceil__" , "__floor__" , "__trunc__" ,
21+ "__length_hint__" , "__dir__" , "__bytes__"
2022 ]
2123}
2224
@@ -28,17 +30,19 @@ predicate is_binary_op(string name) {
2830 "__and__" , "__xor__" , "__or__" , "__ne__" , "__radd__" , "__rsub__" , "__rmul__" , "__rfloordiv__" ,
2931 "__rdiv__" , "__rtruediv__" , "__rmod__" , "__rdivmod__" , "__rpow__" , "__rlshift__" , "__gt__" ,
3032 "__rrshift__" , "__rand__" , "__rxor__" , "__ror__" , "__iadd__" , "__isub__" , "__imul__" ,
31- "__ifloordiv__" , "__idiv__" , "__itruediv__" , "__ge__" , "__imod__" , "__idivmod__" , "__ipow__" ,
32- "__ilshift__" , "__irshift__" , "__iand__" , "__ixor__" , "__ior__" , "__coerce__" , "__cmp__" ,
33- "__rcmp__" , "__getattr___" , "__getattribute___"
33+ "__ifloordiv__" , "__idiv__" , "__itruediv__" , "__ge__" , "__imod__" , "__ipow__" , "__ilshift__" ,
34+ "__irshift__" , "__iand__" , "__ixor__" , "__ior__" , "__coerce__" , "__cmp__" , "__rcmp__" ,
35+ "__getattr__" , "__getattribute__" , "__buffer__" , "__release_buffer__" , "__matmul__" ,
36+ "__rmatmul__" , "__imatmul__" , "__missing__" , "__class_getitem__" , "__mro_entries__" ,
37+ "__format__"
3438 ]
3539}
3640
3741predicate is_ternary_op ( string name ) {
38- name in [ "__setattr__" , "__set__" , "__setitem__" , "__getslice__" , "__delslice__" ]
42+ name in [ "__setattr__" , "__set__" , "__setitem__" , "__getslice__" , "__delslice__" , "__set_name__" ]
3943}
4044
41- predicate is_quad_op ( string name ) { name = "__setslice__" or name = "__exit__" }
45+ predicate is_quad_op ( string name ) { name in [ "__setslice__" , "__exit__" , "__aexit__" ] }
4246
4347int argument_count ( string name ) {
4448 is_unary_op ( name ) and result = 1
@@ -97,6 +101,27 @@ predicate incorrect_pow(
97101 )
98102}
99103
104+ predicate incorrect_round (
105+ Function func , string message , boolean show_counts , boolean is_unused_default
106+ ) {
107+ exists ( int correction | correction = staticmethod_correction ( func ) |
108+ func .getMaxPositionalArguments ( ) < 1 - correction and
109+ message = "Too few parameters" and
110+ show_counts = true and
111+ is_unused_default = false
112+ or
113+ func .getMinPositionalArguments ( ) > 2 - correction and
114+ message = "Too many parameters" and
115+ show_counts = true and
116+ is_unused_default = false
117+ or
118+ func .getMinPositionalArguments ( ) = 2 - correction and
119+ message = "Second parameter to __round__ should have a default value" and
120+ show_counts = false and
121+ is_unused_default = false
122+ )
123+ }
124+
100125predicate incorrect_get (
101126 Function func , string message , boolean show_counts , boolean is_unused_default
102127) {
@@ -160,6 +185,8 @@ where
160185 or
161186 incorrect_get ( f .getScope ( ) , message , show_counts , show_unused_defaults ) and name = "__get__"
162187 or
188+ incorrect_round ( f .getScope ( ) , message , show_counts , show_unused_defaults ) and
189+ name = "__round__"
163190 ) and
164191 not isLikelyPlaceholderFunction ( f .getScope ( ) ) and
165192 show_unused_defaults = false and
0 commit comments