mirror of
				https://github.com/python/cpython.git
				synced 2025-10-29 20:51:26 +00:00 
			
		
		
		
	Replace usage of List[...] with list[...] in typing docs (GH-28821)
The ``List[...]`` form is deprecated since 3.9.
This commit is contained in:
		
							parent
							
								
									b108db63e0
								
							
						
					
					
						commit
						a98b273ce4
					
				
					 1 changed files with 8 additions and 8 deletions
				
			
		|  | @ -975,16 +975,16 @@ These can be used as types in annotations using ``[]``, each having a unique syn | ||||||
| 
 | 
 | ||||||
|       For example:: |       For example:: | ||||||
| 
 | 
 | ||||||
|          def is_str_list(val: List[object]) -> TypeGuard[List[str]]: |          def is_str_list(val: list[object]) -> TypeGuard[list[str]]: | ||||||
|              '''Determines whether all objects in the list are strings''' |              '''Determines whether all objects in the list are strings''' | ||||||
|              return all(isinstance(x, str) for x in val) |              return all(isinstance(x, str) for x in val) | ||||||
| 
 | 
 | ||||||
|          def func1(val: List[object]): |          def func1(val: list[object]): | ||||||
|              if is_str_list(val): |              if is_str_list(val): | ||||||
|                  # Type of ``val`` is narrowed to ``List[str]``. |                  # Type of ``val`` is narrowed to ``list[str]``. | ||||||
|                  print(" ".join(val)) |                  print(" ".join(val)) | ||||||
|              else: |              else: | ||||||
|                  # Type of ``val`` remains as ``List[object]``. |                  # Type of ``val`` remains as ``list[object]``. | ||||||
|                  print("Not a list of strings!") |                  print("Not a list of strings!") | ||||||
| 
 | 
 | ||||||
|    If ``is_str_list`` is a class or instance method, then the type in |    If ``is_str_list`` is a class or instance method, then the type in | ||||||
|  | @ -999,8 +999,8 @@ These can be used as types in annotations using ``[]``, each having a unique syn | ||||||
| 
 | 
 | ||||||
|       ``TypeB`` need not be a narrower form of ``TypeA`` -- it can even be a |       ``TypeB`` need not be a narrower form of ``TypeA`` -- it can even be a | ||||||
|       wider form. The main reason is to allow for things like |       wider form. The main reason is to allow for things like | ||||||
|       narrowing ``List[object]`` to ``List[str]`` even though the latter |       narrowing ``list[object]`` to ``list[str]`` even though the latter | ||||||
|       is not a subtype of the former, since ``List`` is invariant. |       is not a subtype of the former, since ``list`` is invariant. | ||||||
|       The responsibility of writing type-safe type guards is left to the user. |       The responsibility of writing type-safe type guards is left to the user. | ||||||
| 
 | 
 | ||||||
|    ``TypeGuard`` also works with type variables.  For more information, see |    ``TypeGuard`` also works with type variables.  For more information, see | ||||||
|  | @ -2065,8 +2065,8 @@ Introspection helpers | ||||||
| .. class:: ForwardRef | .. class:: ForwardRef | ||||||
| 
 | 
 | ||||||
|    A class used for internal typing representation of string forward references. |    A class used for internal typing representation of string forward references. | ||||||
|    For example, ``List["SomeClass"]`` is implicitly transformed into |    For example, ``list["SomeClass"]`` is implicitly transformed into | ||||||
|    ``List[ForwardRef("SomeClass")]``.  This class should not be instantiated by |    ``list[ForwardRef("SomeClass")]``.  This class should not be instantiated by | ||||||
|    a user, but may be used by introspection tools. |    a user, but may be used by introspection tools. | ||||||
| 
 | 
 | ||||||
|    .. note:: |    .. note:: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Micael Jarniac
						Micael Jarniac