diff --git a/src/betterproto/casing.py b/src/betterproto/casing.py index cd3c34472..485856c9f 100644 --- a/src/betterproto/casing.py +++ b/src/betterproto/casing.py @@ -135,4 +135,8 @@ def lowercase_first(value: str) -> str: def sanitize_name(value: str) -> str: # https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles - return f"{value}_" if keyword.iskeyword(value) else value + if keyword.iskeyword(value): + return f"{value}_" + if value[0].isdigit(): + return f"_{value}" + return value