MCPcopy Index your code
hub / github.com/github/copilot-sdk / getOrCreatePyEnum

Function getOrCreatePyEnum

scripts/codegen/python.ts:1840–1879  ·  view source on GitHub ↗
(
    enumName: string,
    values: string[],
    ctx: PyCodegenCtx,
    description?: string,
    enumValueDescriptions?: EnumValueDescriptions,
    deprecated?: boolean,
    experimental?: boolean
)

Source from the content-addressed store, hash-verified

1838}
1839
1840function getOrCreatePyEnum(
1841 enumName: string,
1842 values: string[],
1843 ctx: PyCodegenCtx,
1844 description?: string,
1845 enumValueDescriptions?: EnumValueDescriptions,
1846 deprecated?: boolean,
1847 experimental?: boolean
1848): string {
1849 const existing = ctx.enumsByName.get(enumName);
1850 if (existing) {
1851 return existing;
1852 }
1853
1854 const lines: string[] = [];
1855 if (experimental) {
1856 pushPyExperimentalComment(lines, "enum");
1857 }
1858 if (deprecated) {
1859 lines.push(`# Deprecated: this enum is deprecated and will be removed in a future version.`);
1860 }
1861 if (description) {
1862 lines.push(`class ${enumName}(Enum):`);
1863 lines.push(` ${pyDocstringLiteral(description)}`);
1864 } else {
1865 lines.push(`class ${enumName}(Enum):`);
1866 }
1867 for (const value of values) {
1868 const valueDescription = enumValueDescriptions?.[value];
1869 if (valueDescription) {
1870 for (const line of valueDescription.split(/\r?\n/)) {
1871 lines.push(` # ${line.trimEnd()}`);
1872 }
1873 }
1874 lines.push(` ${toEnumMemberName(value)} = ${JSON.stringify(value)}`);
1875 }
1876 ctx.enumsByName.set(enumName, enumName);
1877 ctx.enums.push(lines.join("\n"));
1878 return enumName;
1879}
1880
1881function resolvePyPropertyType(
1882 propSchema: JSONSchema7,

Callers 3

getPyNamedSchemaTypeFunction · 0.85
resolvePyPropertyTypeFunction · 0.85

Calls 7

pyDocstringLiteralFunction · 0.85
toEnumMemberNameFunction · 0.85
joinMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…