mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-24 21:14:00 -07:00 
			
		
		
		
	Avoid key names which are valid attributes for data types in Python.
Closes #12990. Alternative to #12992 This PR excludes all attributes of the following data types: lists, tuples, dicts, sets, integers, floats, strings and Unicode objects. It is expected that only the attributes of dicts and sets would cause an problem like in #12990.
This commit is contained in:
		
					parent
					
						
							
								7368030651
							
						
					
				
			
			
				commit
				
					
						ad0d299c56
					
				
			
		
					 1 changed files with 4 additions and 1 deletions
				
			
		|  | @ -36,7 +36,10 @@ Variable names should be letters, numbers, and underscores.  Variables should al | |||
| 
 | ||||
| ``foo-port``, ``foo port``, ``foo.port`` and ``12`` are not valid variable names. | ||||
| 
 | ||||
| Easy enough, let's move on. | ||||
| When you work with more complex data types like dictionaries and sets note that you should avoid keys which are valid attributes for a data type in Python. | ||||
| As a rule of thump, avoid all key names that start and end with two underscores for example ``__do_not_use__``. | ||||
| Also avoid any of the following words: | ||||
| ``add``, ``append``, ``as_integer_ratio``, ``bit_length``, ``capitalize``, ``center``, ``clear``, ``conjugate``, ``copy``, ``count``, ``decode``, ``denominator``, ``difference``, ``difference_update``, ``discard``, ``encode``, ``endswith``, ``expandtabs``, ``extend``, ``find``, ``format``, ``fromhex``, ``fromkeys``, ``get``, ``has_key``, ``hex``, ``imag``, ``index``, ``insert``, ``intersection``, ``intersection_update``, ``isalnum``, ``isalpha``, ``isdecimal``, ``isdigit``, ``isdisjoint``, ``is_integer``, ``islower``, ``isnumeric``, ``isspace``, ``issubset``, ``issuperset``, ``istitle``, ``isupper``, ``items``, ``iteritems``, ``iterkeys``, ``itervalues``, ``join``, ``keys``, ``ljust``, ``lower``, ``lstrip``, ``numerator``, ``partition``, ``pop``, ``popitem``, ``real``, ``remove``, ``replace``, ``reverse``, ``rfind``, ``rindex``, ``rjust``, ``rpartition``, ``rsplit``, ``rstrip``, ``setdefault``, ``sort``, ``split``, ``splitlines``, ``startswith``, ``strip``, ``swapcase``, ``symmetric_difference``, ``symmetric_difference_update``, ``title``, ``translate``, ``union``, ``update``, ``upper``, ``values``, ``viewitems``, ``viewkeys``, ``viewvalues``, ``zfill``. | ||||
| 
 | ||||
| .. _variables_in_inventory: | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue