Changeset View
Changeset View
Standalone View
Standalone View
test/lint/check-rpc-mappings.py
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | for cmd in cmds: | ||||
all_methods_by_argname[argname].append(cmd.name) | all_methods_by_argname[argname].append(cmd.name) | ||||
converts_by_argname[argname].append(arg.convert) | converts_by_argname[argname].append(arg.convert) | ||||
for argname, convert in converts_by_argname.items(): | for argname, convert in converts_by_argname.items(): | ||||
if all(convert) != any(convert): | if all(convert) != any(convert): | ||||
if argname in IGNORE_DUMMY_ARGS: | if argname in IGNORE_DUMMY_ARGS: | ||||
# these are testing or dummy, don't warn for them | # these are testing or dummy, don't warn for them | ||||
continue | continue | ||||
print('WARNING: conversion mismatch for argument named {} ({})'.format( | formattedCommands = [] | ||||
argname, list(zip(all_methods_by_argname[argname], converts_by_argname[argname])))) | for (cmd, convert) in list( | ||||
zip(all_methods_by_argname[argname], converts_by_argname[argname])): | |||||
argType = 'string' | |||||
if convert: | |||||
argType = 'JSON' | |||||
formattedCommands.append( | |||||
"'{}' has argument '{}' of type '{}'".format( | |||||
cmd, argname, argType)) | |||||
print("WARNING: In order to keep a consistent API, arguments of the same name are expected to either both " | |||||
"be string-typed or converted from JSON. But there was a conversion mismatch: {}. " | |||||
"Common root causes for this warning: 1) The command and/or argument are missing from the conversion " | |||||
"table in '{}'. 2) Arguments of the same name are being converted from JSON for some commands, but not " | |||||
"for others. Consider renaming arguments such that one name is used for strings and the other for " | |||||
"conversions from JSON.".format(formattedCommands, SOURCE_CLIENT)) | |||||
sys.exit(0) | sys.exit(0) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |