Skip to content

Commit cf692a1

Browse files
committed
Add comments in the is_copy_constructor method
Cherry-picked from develop branch
1 parent ad7a595 commit cf692a1

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

pygccxml/declarations/calldef.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,22 +736,37 @@ def __str__(self):
736736

737737
@property
738738
def is_copy_constructor(self):
739-
"""returns True if described declaration is copy constructor,
740-
otherwise False"""
739+
"""
740+
Returns True if described declaration is copy constructor,
741+
otherwise False
742+
743+
"""
744+
741745
from . import type_traits
746+
742747
args = self.arguments
743-
if 1 != len(args):
748+
749+
# A copy constructor has only one argument
750+
if len(args) != 1:
744751
return False
752+
753+
# We have only one argument, get it
745754
arg = args[0]
755+
756+
# The argument needs to be passed by reference in a copy constructor
746757
if not type_traits.is_reference(arg.type):
747758
return False
759+
760+
# The argument needs to be const for a copy constructor
748761
if not type_traits.is_const(arg.type.base):
749762
return False
750-
unaliased = type_traits.remove_alias(arg.type.base)
751-
# unaliased now refers to const_t instance
752-
if not isinstance(unaliased.base, cpptypes.declarated_t):
763+
764+
un_aliased = type_traits.remove_alias(arg.type.base)
765+
# un_aliased now refers to const_t instance
766+
if not isinstance(un_aliased.base, cpptypes.declarated_t):
753767
return False
754-
return id(unaliased.base.declaration) == id(self.parent)
768+
769+
return id(un_aliased.base.declaration) == id(self.parent)
755770

756771
@property
757772
def is_trivial_constructor(self):

0 commit comments

Comments
 (0)