Skip to content

Commit

Permalink
Rename a method argument to avoid a double negation.
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Sep 6, 2024
1 parent 3ef92d1 commit d097e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 7 additions & 2 deletions Cython/Compiler/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14101,15 +14101,20 @@ def calculate_result_code(self):

def generate_result_code(self, code):
if self.type.typeobj_is_available():
allow_none = not self.notnone
if self.type.is_builtin_type:
type_test = self.type.type_test_code(
self.arg.py_result(),
self.notnone, exact=self.exact_builtin_type)
allow_none,
exact=self.exact_builtin_type,
)
code.globalstate.use_utility_code(UtilityCode.load_cached(
"RaiseUnexpectedTypeError", "ObjectHandling.c"))
else:
type_test = self.type.type_test_code(
self.arg.py_result(), self.notnone)
self.arg.py_result(),
allow_none,
)
code.globalstate.use_utility_code(
UtilityCode.load_cached("ExtTypeTest", "ObjectHandling.c"))
code.putln("if (!(%s)) %s" % (
Expand Down
18 changes: 7 additions & 11 deletions Cython/Compiler/PyrexTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,10 +1499,10 @@ def type_check_function(self, exact=True):
def isinstance_code(self, arg):
return '%s(%s)' % (self.type_check_function(exact=False), arg)

def type_test_code(self, arg, notnone=False, exact=True):
def type_test_code(self, arg, allow_none=True, exact=True):
type_check = self.type_check_function(exact=exact)
check = f'likely({type_check}({arg}))'
if not notnone:
if allow_none:
check += f'||(({arg}) == Py_None)'
return check + f' || __Pyx_RaiseUnexpectedTypeError("{self.name}", {arg})'

Expand Down Expand Up @@ -1640,15 +1640,11 @@ def declaration_code(self, entity_code,
entity_code = "*%s" % entity_code
return self.base_declaration_code(base_code, entity_code)

def type_test_code(self, py_arg, notnone=False):

none_check = "((%s) == Py_None)" % py_arg
type_check = "likely(__Pyx_TypeTest(%s, %s))" % (
py_arg, self.typeptr_cname)
if notnone:
return type_check
else:
return "likely(%s || %s)" % (none_check, type_check)
def type_test_code(self, py_arg, allow_none=True):
type_check = f"likely(__Pyx_TypeTest({py_arg}, {self.typeptr_cname}))"
if allow_none:
type_check = f"likely((({py_arg}) == Py_None) || {type_check})"
return type_check

def attributes_known(self):
return self.scope is not None
Expand Down

0 comments on commit d097e76

Please sign in to comment.