Skip to content

Commit

Permalink
minor style improvements
Browse files Browse the repository at this point in the history
dependencies.py:
- In a comment, rename "imported modules" to "linked modules"
- Check against "macro" only in one loop, not in both

__main__.py: avoid an odd use of any() where regular `or` does the
trick.

ctypesdescs: avoid unnecessary explicit True/False for statement that
results in a bool already
  • Loading branch information
mara004 committed Jan 17, 2024
1 parent 6ff2da9 commit 467ba81
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ctypesgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def __call__(self, parser, namespace, values, option_string=None):

args = parser.parse_args(given_argv)

if not any([args.headers, args.system_headers]):
if not (args.headers or args.system_headers):
raise argparse.ArgumentError("Either --headers or --system-headers required.")

if args.cpp:
Expand Down
2 changes: 1 addition & 1 deletion ctypesgen/ctypedescs.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def __init__(self, tag, attrib, variety, members, src=None):
self.attrib = attrib
self.variety = variety # "struct" or "union"
self.members = members
self.opaque = True if self.members is None else False
self.opaque = self.members is None
self.src = src

if type(self.tag) == int or not self.tag:
Expand Down
13 changes: 6 additions & 7 deletions ctypesgen/processor/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def find_dependencies(data, opts):
typedef_names = {}
ident_names = {}

# Start the lookup tables with names from imported modules
# Start the lookup tables with names from linked modules

for name in opts.linked_symbols:
typedef_names[name] = None
Expand Down Expand Up @@ -155,12 +155,11 @@ def add_to_lookup_table(desc, kind):
# Macros are handled differently from everything else because macros can
# call other macros that are referenced after them in the input file, but
# no other type of description can look ahead like that.


macros = []
for kind, desc in data.output_order:
add_to_lookup_table(desc, kind)
if kind != "macro":
find_dependencies_for(desc, kind)
find_dependencies_for(desc, kind) if kind != "macro" else macros.append(desc)

for kind, desc in data.output_order:
if kind == "macro":
find_dependencies_for(desc, kind)
for desc in macros:
find_dependencies_for(desc, "macro")
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def generate(header, args=[], lang="py", sys_header=False):
# - The default file encoding seems to be cp1252, which is problematic with special chars (such as the banana in the constants test). Need to specify UTF-8 explicitly. PEP 686 should hopefully improve this.

# Use custom tempfiles scoping so we may retain data for inspection
# FIXME can cause confusion with partial test suite runs - static naming by test case would be better, also more descriptive
# FIXME can cause confusion with partial test suite runs - static naming by test case would be better, including more descriptive
global COUNTER; COUNTER += 1

cmdargs = []
Expand Down Expand Up @@ -85,9 +85,6 @@ def generate(header, args=[], lang="py", sys_header=False):
assert False


# -- Functions facilitating tests of use of cross inclusion --


def generate_common():
common_lib = "libcommon.dll" if sys.platform == "win32" else "libcommon.so"
_create_common_files()
Expand Down

0 comments on commit 467ba81

Please sign in to comment.