Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix authored Nov 20, 2023
1 parent 070ec4f commit 9be1ac3
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 84 deletions.
44 changes: 22 additions & 22 deletions python/libgrass_interface_generator/ctypesgen/ctypedescs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@


# This protocol is used for walking type trees.
class CtypesTypeVisitor:
class CtypesTypeVisitor(object):
def visit_struct(self, struct):
pass

Expand Down Expand Up @@ -135,9 +135,9 @@ def remove_function_pointer(t):
return t


class CtypesType:
class CtypesType(object):
def __init__(self):
super().__init__()
super(CtypesType, self).__init__()
self.errors = []

def __repr__(self):
Expand All @@ -155,7 +155,7 @@ class CtypesSimple(CtypesType):
"""Represents a builtin type, like "char" or "int"."""

def __init__(self, name, signed, longs):
super().__init__()
super(CtypesSimple, self).__init__()
self.name = name
self.signed = signed
self.longs = longs
Expand All @@ -166,7 +166,7 @@ def py_string(self, ignore_can_be_ctype=None):

class CtypesSpecial(CtypesType):
def __init__(self, name):
super().__init__()
super(CtypesSpecial, self).__init__()
self.name = name

def py_string(self, ignore_can_be_ctype=None):
Expand All @@ -177,58 +177,58 @@ class CtypesTypedef(CtypesType):
"""Represents a type defined by a typedef."""

def __init__(self, name):
super().__init__()
super(CtypesTypedef, self).__init__()
self.name = name

def visit(self, visitor):
if not self.errors:
visitor.visit_typedef(self.name)
super().visit(visitor)
super(CtypesTypedef, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
return self.name


class CtypesBitfield(CtypesType):
def __init__(self, base, bitfield):
super().__init__()
super(CtypesBitfield, self).__init__()
self.base = base
self.bitfield = bitfield

def visit(self, visitor):
self.base.visit(visitor)
super().visit(visitor)
super(CtypesBitfield, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
return self.base.py_string()


class CtypesPointer(CtypesType):
def __init__(self, destination, qualifiers):
super().__init__()
super(CtypesPointer, self).__init__()
self.destination = destination
self.qualifiers = qualifiers

def visit(self, visitor):
if self.destination:
self.destination.visit(visitor)
super().visit(visitor)
super(CtypesPointer, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
return "POINTER(%s)" % self.destination.py_string()


class CtypesArray(CtypesType):
def __init__(self, base, count):
super().__init__()
super(CtypesArray, self).__init__()
self.base = base
self.count = count

def visit(self, visitor):
self.base.visit(visitor)
if self.count:
self.count.visit(visitor)
super().visit(visitor)
super(CtypesArray, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
if self.count is None:
Expand All @@ -239,7 +239,7 @@ def py_string(self, ignore_can_be_ctype=None):
return "%s * int(%s)" % (self.base.py_string(), self.count.py_string(False))


class CtypesNoErrorCheck:
class CtypesNoErrorCheck(object):
def py_string(self, ignore_can_be_ctype=None):
return "None"

Expand All @@ -249,7 +249,7 @@ def __bool__(self):
__nonzero__ = __bool__


class CtypesPointerCast:
class CtypesPointerCast(object):
def __init__(self, target):
self.target = target

Expand All @@ -259,7 +259,7 @@ def py_string(self, ignore_can_be_ctype=None):

class CtypesFunction(CtypesType):
def __init__(self, restype, parameters, variadic, attrib=dict()):
super().__init__()
super(CtypesFunction, self).__init__()
self.restype = restype
self.errcheck = CtypesNoErrorCheck()

Expand Down Expand Up @@ -291,7 +291,7 @@ def visit(self, visitor):
self.restype.visit(visitor)
for a in self.argtypes:
a.visit(visitor)
super().visit(visitor)
super(CtypesFunction, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
return "CFUNCTYPE(UNCHECKED(%s), %s)" % (
Expand Down Expand Up @@ -319,7 +319,7 @@ def anonymous_struct_tag():

class CtypesStruct(CtypesType):
def __init__(self, tag, attrib, variety, members, src=None):
super().__init__()
super(CtypesStruct, self).__init__()
self.tag = tag
self.attrib = attrib
self.variety = variety # "struct" or "union"
Expand All @@ -342,7 +342,7 @@ def __init__(self, tag, attrib, variety, members, src=None):
self.src = src

def get_required_types(self):
types = super().get_required_types()
types = super(CtypesStruct, self).get_required_types()
types.add((self.variety, self.tag))
return types

Expand All @@ -351,7 +351,7 @@ def visit(self, visitor):
if not self.opaque:
for name, ctype in self.members:
ctype.visit(visitor)
super().visit(visitor)
super(CtypesStruct, self).visit(visitor)

def get_subtypes(self):
if self.opaque:
Expand All @@ -374,7 +374,7 @@ def anonymous_enum_tag():

class CtypesEnum(CtypesType):
def __init__(self, tag, enumerators, src=None):
super().__init__()
super(CtypesEnum, self).__init__()
self.tag = tag
self.enumerators = enumerators

Expand All @@ -393,7 +393,7 @@ def __init__(self, tag, enumerators, src=None):

def visit(self, visitor):
visitor.visit_enum(self)
super().visit(visitor)
super(CtypesEnum, self).visit(visitor)

def py_string(self, ignore_can_be_ctype=None):
return "enum_%s" % self.tag
22 changes: 11 additions & 11 deletions python/libgrass_interface_generator/ctypesgen/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""


class DescriptionCollection:
class DescriptionCollection(object):
"""Represents a collection of Descriptions."""

def __init__(
Expand All @@ -24,12 +24,12 @@ def __init__(
self.output_order = output_order


class Description:
class Description(object):
"""Represents a constant, typedef, struct, function, variable, enum,
or macro description. Description is an abstract base class."""

def __init__(self, src=None):
super().__init__()
super(Description, self).__init__()
self.src = src # A tuple of (filename, lineno)

# If object will be included in output file. Values are "yes", "never",
Expand Down Expand Up @@ -82,7 +82,7 @@ class ConstantDescription(Description):
"""Simple class to contain information about a constant."""

def __init__(self, name, value, src=None):
super().__init__(src)
super(ConstantDescription, self).__init__(src)
# Name of constant, a string
self.name = name
# Value of constant, as an ExpressionNode object
Expand All @@ -102,7 +102,7 @@ class TypedefDescription(Description):
"""Simple container class for a type definition."""

def __init__(self, name, ctype, src=None):
super().__init__(src)
super(TypedefDescription, self).__init__(src)
self.name = name # Name, a string
self.ctype = ctype # The base type as a ctypedescs.CtypeType object

Expand All @@ -120,7 +120,7 @@ class StructDescription(Description):
"""Simple container class for a structure or union definition."""

def __init__(self, tag, attrib, variety, members, opaque, ctype, src=None):
super().__init__(src)
super(StructDescription, self).__init__(src)
# The name of the structure minus the "struct" or "union"
self.tag = tag
self.attrib = attrib
Expand All @@ -147,7 +147,7 @@ class EnumDescription(Description):
"""Simple container class for an enum definition."""

def __init__(self, tag, members, ctype, src=None):
super().__init__(src)
super(EnumDescription, self).__init__(src)
# The name of the enum, minus the "enum"
self.tag = tag
# A list of (name,value) pairs where value is a number
Expand All @@ -169,7 +169,7 @@ class FunctionDescription(Description):
"""Simple container class for a C function."""

def __init__(self, name, restype, argtypes, errcheck, variadic, attrib, src):
super().__init__(src)
super(FunctionDescription, self).__init__(src)
# Name, a string
self.name = name
# Name according to C - stored in case description is renamed
Expand Down Expand Up @@ -199,7 +199,7 @@ class VariableDescription(Description):
"""Simple container class for a C variable declaration."""

def __init__(self, name, ctype, src=None):
super().__init__(src)
super(VariableDescription, self).__init__(src)
# Name, a string
self.name = name
# Name according to C - stored in case description is renamed
Expand All @@ -221,7 +221,7 @@ class MacroDescription(Description):
"""Simple container class for a C macro."""

def __init__(self, name, params, expr, src=None):
super().__init__(src)
super(MacroDescription, self).__init__(src)
self.name = name
self.params = params
self.expr = expr # ExpressionNode for the macro's body
Expand All @@ -240,7 +240,7 @@ class UndefDescription(Description):
"""Simple container class for a preprocessor #undef directive."""

def __init__(self, macro, src=None):
super().__init__(src)
super(UndefDescription, self).__init__(src)
self.include_rule = "if_needed"

self.macro = macro
Expand Down
4 changes: 2 additions & 2 deletions python/libgrass_interface_generator/ctypesgen/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class is ExpressionNode. ExpressionNode's most useful method is py_string(),
# On the other hand, this would be a challenge to write.


class EvaluationContext:
class EvaluationContext(object):
"""Interface for evaluating expression nodes."""

def evaluate_identifier(self, name):
Expand All @@ -45,7 +45,7 @@ def evaluate_parameter(self, name):
return 0


class ExpressionNode:
class ExpressionNode(object):
def __init__(self):
self.errors = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Lookup:
mode = ctypes.DEFAULT_MODE

def __init__(self, path):
super().__init__()
super(LibraryLoader.Lookup, self).__init__()
self.access = dict(cdecl=ctypes.CDLL(path, self.mode))

def get(self, name, calling_convention="cdecl"):
Expand Down Expand Up @@ -279,7 +279,7 @@ def _get_ld_so_conf_dirs(self, conf, dirs):
else:
for dir2 in glob.glob(match.group("pattern")):
self._get_ld_so_conf_dirs(dir2, dirs)
except OSError:
except IOError:
pass

def _create_ld_so_cache(self):
Expand Down Expand Up @@ -382,7 +382,7 @@ class Lookup(LibraryLoader.Lookup):
"""Lookup class for Windows libraries..."""

def __init__(self, path):
super().__init__(path)
super(WindowsLibraryLoader.Lookup, self).__init__(path)
self.access["stdcall"] = ctypes.windll.LoadLibrary(path)


Expand Down
Loading

0 comments on commit 9be1ac3

Please sign in to comment.