/*** @name Builtin shadowed by local variable* @description Defining a local variable with the same name as a built-in object* makes the built-in object unusable within the current scope and makes the code* more difficult to read.* @kind problem* @tags quality* maintainability* readability* correctness* @problem.severity recommendation* @sub-severity low* @precision medium* @id py/local-shadows-builtin*/import pythonimport Shadowingimport semmle.python.types.Builtinspredicate allow_list(string name) {name in [/* These are rarely used and thus unlikely to be confusing */"iter", "next", "input", "file", "apply", "slice", "buffer", "coerce", "intern", "exit","quit", "license",/* These are short and/or hard to avoid */"dir", "id", "max", "min", "sum", "cmp", "chr", "ord", "bytes", "_",]}predicate shadows(Name d, string name, Function scope, int line) {exists(LocalVariable l |d.defines(l) andl.getId() = name andexists(Builtin::builtin(l.getId()))) andd.getScope() = scope andd.getLocation().getStartLine() = line andnot allow_list(name) andnot optimizing_parameter(d)}predicate first_shadowing_definition(Name d, string name) {exists(int first, Scope scope |shadows(d, name, scope, first) andfirst = min(int line | shadows(_, name, scope, line)))}from Name d, string namewhere first_shadowing_definition(d, name)select d, "Local variable " + name + " shadows a builtin variable."
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。