Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit b1b56ab

Browse files
Aza Tulepbergenovparthea
andauthored
feat: freezes reserved names list. (#1575)
* feat: freezes reserved names list. * chore: fix bugs. * chore: fix bug in async client. * chore: fix bug in test. * chore: update goldens. * chore: revert some files. --------- Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 3fb93a4 commit b1b56ab

2 files changed

Lines changed: 77 additions & 18 deletions

File tree

gapic/utils/reserved_names.py

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,81 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import builtins
16-
import itertools
17-
import keyword
18-
15+
# DO NOT CHANGE this file, except when you need to add a new reserved keyword
16+
# from Python's new major release.
17+
# In an unforseen case if you have to make changes, please follow the process:
18+
# 1. Run the internal script to check if any of the existing Google APIs use the
19+
# item to be added/removed. For external contributors, ask a Googler to do that
20+
# during code review.
21+
# 2. If no APIs are using it, it's safe to add. Otherwise, consult with your TL.
22+
#
23+
# Changing this list will lead to breaking changes. This is happening because
24+
# GAPIC will add "_" to field names from that list. This will change the generated
25+
# client library surface (i.e. breaking change). Example of when this happened:
26+
# https://github.com/googleapis/gapic-generator-python/issues/835.
1927

20-
# The exceptions to builtins are frequent and useful.
21-
# They are explicitly allowed message, module, and field names.
28+
# Each item in the list belongs to one of the following categories:
29+
# 1. Python keyword
30+
# 2. Used in Google APIs at the time of writing this PR
31+
# 3. Reserved word from Protoplus.
2232
RESERVED_NAMES = frozenset(
23-
itertools.chain(
24-
# We CANNOT make exceptions for keywords.
25-
keyword.kwlist,
26-
# We make SOME exceptions for certain names that collide with builtins.
27-
set(dir(builtins)) - {"filter", "map", "id",
28-
"input", "property", "vars", "set"},
29-
# "mapping" and "ignore_unknown_fields" have special uses
30-
# in the constructor of proto.Message
31-
{"mapping", "ignore_unknown_fields"},
32-
)
33+
[
34+
"any",
35+
"format",
36+
"yield",
37+
"await",
38+
"False",
39+
"return",
40+
"continue",
41+
"as",
42+
"pass",
43+
"next",
44+
"class",
45+
"list",
46+
"breakpoint",
47+
"import",
48+
"mapping",
49+
"zip",
50+
"locals",
51+
"max",
52+
"and",
53+
"finally",
54+
"dir",
55+
"def",
56+
"elif",
57+
"from",
58+
"nonlocal",
59+
"min",
60+
"not",
61+
"object",
62+
"global",
63+
"with",
64+
"else",
65+
"__peg_parser__",
66+
"del",
67+
"range",
68+
"open",
69+
"assert",
70+
"all",
71+
"except",
72+
"while",
73+
"license",
74+
"raise",
75+
"True",
76+
"lambda",
77+
"for",
78+
"or",
79+
"if",
80+
"in",
81+
"async",
82+
"slice",
83+
"is",
84+
"break",
85+
"hash",
86+
"None",
87+
"try",
88+
"type",
89+
# Comes from Protoplus
90+
"ignore_unknown_fields"
91+
]
3392
)

tests/unit/utils/test_uri_conv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020

2121
def test_convert_uri_fieldname():
22-
uri = "abc/*/license/{license}/{xyz.reversed=reversed/*}"
23-
expected_uri = "abc/*/license/{license_}/{xyz.reversed_=reversed/*}"
22+
uri = "abc/*/license/{license}/{xyz.class=class/*}"
23+
expected_uri = "abc/*/license/{license_}/{xyz.class_=class/*}"
2424
assert utils.convert_uri_fieldnames(uri) == expected_uri
2525

2626

0 commit comments

Comments
 (0)