SCR108: duplicate-dict-key
Dict literal has the same constant key twice
| Code | SCR108 |
| Name | duplicate-dict-key |
| Category | Scripts (SCR) |
| Default severity | warning |
| Enabled by default | yes |
| Fix available | no |
| ign-lint equivalent | none |
What it does
Section titled “What it does”Reports keys of a dict literal that repeat an earlier constant key, with Python 2.7 equality:
- numbers by value:
1,1L,1.0,Trueand1+0jare the same key, as are0,-0.0,0jandFalse;1e16equals10000000000000000but not10000000000000001; - strings: a
strand aunicodewith the same ASCII text are the same key; astrwith non-ASCII bytes never equals aunicode('\xe9'andu'\xe9'are two keys); None, and tuples of such constants ((1, 2)and(1.0, 2L)).
True, False and None count only where they are Jython's builtins: in
Python 2 True = 2 makes True an ordinary variable, and from x import *, exec or writes through globals() may rebind them.
Number literals with +, - or ~ in front count as constants; other
expressions do not.
Why is this bad?
Section titled “Why is this bad?”Only the last value is kept; the earlier entry is silently lost. In Ignition this often hides a mistake in a payload, a column mapping or a style dict.
Example
Section titled “Example”payload = { "line": line, "machine": machine, "line": station,}Use instead:
payload = { "line": line, "machine": machine, "station": station,}pylint
Section titled “pylint”Corresponds to W0109 duplicate-key.
Generated from the rule metadata by iglint generate-docs; iglint rule SCR108 prints the same page in the terminal. Source: docs/rules/SCR108.md.