You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/development/contributing.rst
+5-5
Original file line number
Diff line number
Diff line change
@@ -804,27 +804,27 @@ Types imports should follow the ``from typing import ...`` convention. So rather
804
804
805
805
import typing
806
806
807
-
primes= [] # type:typing.List[int]
807
+
primes: typing.List[int] = []
808
808
809
809
You should write
810
810
811
811
.. code-block:: python
812
812
813
813
from typing import List, Optional, Union
814
814
815
-
primes= [] # type:List[int]
815
+
primes: List[int] = []
816
816
817
817
``Optional`` should be used where applicable, so instead of
818
818
819
819
.. code-block:: python
820
820
821
-
maybe_primes= [] # type:List[Union[int,None]]
821
+
maybe_primes: List[Union[int, None]] = []
822
822
823
823
You should write
824
824
825
825
.. code-block:: python
826
826
827
-
maybe_primes= [] # type:List[Optional[int]]
827
+
maybe_primes: List[Optional[int]] = []
828
828
829
829
In some cases in the code base classes may define class variables that shadow builtins. This causes an issue as described in `Mypy 1775 <https://github.com/python/mypy/issues/1775#issuecomment-310969854>`_. The defensive solution here is to create an unambiguous alias of the builtin and use that without your annotation. For example, if you come across a definition like
830
830
@@ -840,7 +840,7 @@ The appropriate way to annotate this would be as follows
840
840
str_type =str
841
841
842
842
classSomeClass2:
843
-
str=None# type:str_type
843
+
str: str_type =None
844
844
845
845
In some cases you may be tempted to use ``cast`` from the typing module when you know better than the analyzer. This occurs particularly when using custom inference functions. For example
0 commit comments