MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / drop_namespace_collisions

Function drop_namespace_collisions

scripts/generate-sdk.py:352–378  ·  view source on GitHub ↗

Drop any command whose name is also a namespace prefix of another. e.g. a command "io" cannot coexist with "io.connect": the wrapper for "io" would overwrite the namespace object. These are rare/accidental; skip them and warn rather than emit broken code.

(commands)

Source from the content-addressed store, hash-verified

350
351
352def drop_namespace_collisions(commands):
353 """Drop any command whose name is also a namespace prefix of another.
354
355 e.g. a command "io" cannot coexist with "io.connect": the wrapper for "io"
356 would overwrite the namespace object. These are rare/accidental; skip them
357 and warn rather than emit broken code.
358 """
359 names = {c["name"] for c in commands}
360 prefixes = set()
361 for name in names:
362 parts = name.split(".")
363 for i in range(1, len(parts)):
364 prefixes.add(".".join(parts[:i]))
365
366 kept, dropped = [], []
367 for cmd in commands:
368 if cmd["name"] in prefixes:
369 dropped.append(cmd["name"])
370 else:
371 kept.append(cmd)
372
373 for name in dropped:
374 print(
375 "[sdk] skipping '%s' (name collides with a namespace)" % name,
376 file=sys.stderr,
377 )
378 return kept
379
380
381def collect_symbols(commands):

Callers 1

mainFunction · 0.85

Calls 3

setFunction · 0.50
addMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected