Forbid types in variable name
See original GitHub issueRule request
Thesis
Forbid using built-in type name in the variable name, either as prefix or suffix. It applies to all variable definitions: function arguments, assignments, with
.
# bad
username_str = 'root'
username_str = current_user()
USERNAME_STR = 'root'
str_username = 'root'
# good
username = current_user()
username: str = current_user()
stranger = 'root'
default_user = User()
The rule should be applied to built-in types only: str, int, float, set, dict, and so on. Having context = Context()
is fine.
Reasoning
Type annotations are better, they can be statically checked. Names can get outdated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
You shouldn't name your variables after their types for the ...
A variable's name should be independent of its type. You shouldn't name your variables after their types for the same reason you wouldn't...
Read more >Forbid assigning a variable of type any to a ... - Stack Overflow
S or T is the Any type. This indicates that any type is assignable to "any" and "any" is assignable to any other...
Read more >RANT: Stop Indicating Type in Variable Name Please
compiler knows the type of a variable and will warn, or out and out prevent misuse of the type. Therefore the type info...
Read more >variable-name - Rule
"ban-keywords" : disallows the use of certain TypeScript keywords as variable or parameter names. These are: any , Number , number , String...
Read more >Keywords You Cannot Use as Variable or Constant Names
Some words are reserved by C++, and you cannot use them as variable names. These keywords have special meaning to the C++ compiler....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Good point. Let’s try to classify then
int
(integer),bool
(boolean),dict
(dictionary).frozenset
(frozen set),bytearray
(byte array).float
(hard to imagine context where it means something except floating point number),tuple
(I know it is used for database entities but word “record” is a better synonym),bytes
(can be something like “bytes_count”, probably),complex
(same as float, what else can be complex if not numbers).set
,list
,slice
,type
,range
.It can have other types as well, for example:
module_list = ModuleList()