Skip to content

Commit 2e8a9ad

Browse files
Rework to call hasattr once
1 parent 46ea89a commit 2e8a9ad

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

protovalidate/internal/rules.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@
3232
from buf.validate import validate_pb2
3333
from protovalidate.internal.cel_field_presence import InterpretedRunner, in_has
3434

35-
3635
# protobuf 7+ removed FieldDescriptor.label / LABEL_REPEATED in favour of is_repeated.
37-
def _is_repeated(field: descriptor.FieldDescriptor) -> bool:
38-
if hasattr(field, "is_repeated"):
36+
_FieldDescriptorClass = descriptor.FieldDescriptor
37+
if hasattr(_FieldDescriptorClass, "is_repeated"):
38+
39+
def _is_repeated(field: descriptor.FieldDescriptor) -> bool:
3940
return field.is_repeated
40-
return field.label == descriptor.FieldDescriptor.LABEL_REPEATED
41+
42+
else:
43+
44+
def _is_repeated(field: descriptor.FieldDescriptor) -> bool:
45+
return field.label == descriptor.FieldDescriptor.LABEL_REPEATED
4146

4247

4348
class CompilationError(Exception):

0 commit comments

Comments
 (0)