MCPcopy Index your code
hub / github.com/RustPython/RustPython / dump_bitflags

Function dump_bitflags

scripts/generate_sre_constants.py:61–83  ·  view source on GitHub ↗

Generate Rust bitflags definitions from a Python dictionary. Args: d (dict): The dictionary containing the bitflag variants. prefix (str): The prefix to strip from the variant names. derives (str): The derive attributes to include. struct_name (str): The name of

(d, prefix, derives, struct_name, int_t)

Source from the content-addressed store, hash-verified

59
60
61def dump_bitflags(d, prefix, derives, struct_name, int_t):
62 """Generate Rust bitflags definitions from a Python dictionary.
63
64 Args:
65 d (dict): The dictionary containing the bitflag variants.
66 prefix (str): The prefix to strip from the variant names.
67 derives (str): The derive attributes to include.
68 struct_name (str): The name of the struct to generate.
69 int_t (str): The integer type to use for the bitflags.
70
71 Returns:
72 list: A list of strings representing the bitflags definition.
73 """
74 items = [(value, name) for name, value in d.items() if name.startswith(prefix)]
75 content = ["bitflags! {\n"]
76 content.append(f"{derives}\n") if derives else None
77 content.append(f" pub struct {struct_name}: {int_t} {{\n")
78 for value, name in sorted(items):
79 name = str(name).removeprefix(prefix)
80 content.append(f" const {name} = {value};\n")
81 content.append(" }\n")
82 content.append("}\n\n")
83 return content
84
85
86def main(

Callers 1

mainFunction · 0.85

Calls 6

sortedFunction · 0.85
strFunction · 0.85
itemsMethod · 0.45
startswithMethod · 0.45
appendMethod · 0.45
removeprefixMethod · 0.45

Tested by

no test coverage detected