File tree Expand file tree Collapse file tree 6 files changed +37
-0
lines changed Expand file tree Collapse file tree 6 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -817,6 +817,15 @@ section of the command line docs.
817
817
Note: the exact list of flags enabled by :confval: `strict ` may
818
818
change over time.
819
819
820
+ .. confval :: user_builtins_name
821
+
822
+ :type: comma-separated list of strings
823
+
824
+ Disable name-defined error checking for the given values.
825
+
826
+ Note: This setting should be used *only * if new values have beed defined
827
+ into the ``builtins `` module.
828
+
820
829
821
830
Configuring error messages
822
831
**************************
Original file line number Diff line number Diff line change @@ -193,6 +193,7 @@ def split_commas(value: str) -> list[str]:
193
193
"exclude" : lambda s : [s .strip ()],
194
194
"packages" : try_split ,
195
195
"modules" : try_split ,
196
+ "user_builtins_name" : try_split ,
196
197
}
197
198
198
199
# Reuse the ini_config_types and overwrite the diff
@@ -215,6 +216,7 @@ def split_commas(value: str) -> list[str]:
215
216
"exclude" : str_or_array_as_list ,
216
217
"packages" : try_split ,
217
218
"modules" : try_split ,
219
+ "user_builtins_name" : try_split ,
218
220
}
219
221
)
220
222
Original file line number Diff line number Diff line change @@ -1282,6 +1282,13 @@ def add_invertible_flag(
1282
1282
),
1283
1283
group = code_group ,
1284
1284
)
1285
+ code_group .add_argument (
1286
+ "--user-builtins-name" ,
1287
+ action = "append" ,
1288
+ metavar = "NAME" ,
1289
+ default = [],
1290
+ help = "List of name to ignore; can repeat for more names" ,
1291
+ )
1285
1292
code_group .add_argument (
1286
1293
"-m" ,
1287
1294
"--module" ,
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class BuildType:
55
55
"strict_concatenate" ,
56
56
"strict_equality" ,
57
57
"strict_optional" ,
58
+ "user_builtins_name" ,
58
59
"warn_no_return" ,
59
60
"warn_return_any" ,
60
61
"warn_unreachable" ,
@@ -138,6 +139,8 @@ def __init__(self) -> None:
138
139
# File names, directory names or subpaths to avoid checking
139
140
self .exclude : list [str ] = []
140
141
self .exclude_gitignore : bool = False
142
+ # User defined builtins names to skip name-defined checking
143
+ self .user_builtins_name : list [str ] = []
141
144
142
145
# disallow_any options
143
146
self .disallow_any_generics = False
Original file line number Diff line number Diff line change @@ -6340,6 +6340,9 @@ def lookup(
6340
6340
return None
6341
6341
node = table [name ]
6342
6342
return node
6343
+ # 6. User Defined Builtins
6344
+ if name in self .options .user_builtins_name :
6345
+ return None
6343
6346
# Give up.
6344
6347
if not implicit_name and not suppress_errors :
6345
6348
self .name_not_defined (name , ctx )
Original file line number Diff line number Diff line change @@ -1507,3 +1507,16 @@ def bad_kwargs(**kwargs: Unpack[TVariadic]): # E: Unpack item in ** argument mu
1507
1507
pass
1508
1508
1509
1509
[builtins fixtures/dict.pyi]
1510
+
1511
+ [case testUserBuiltinsName]
1512
+ # flags: --user-builtins-name foo
1513
+ foo()
1514
+ egg()
1515
+ [out]
1516
+ main:3: error: Name "egg" is not defined
1517
+
1518
+ [case testUserBuiltinsNameMultiple]
1519
+ # flags: --user-builtins-name foo --user-builtins-name egg
1520
+ foo()
1521
+ egg()
1522
+ [out]
You can’t perform that action at this time.
0 commit comments