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: docs/source/common_issues.rst
+50-28Lines changed: 50 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,12 +72,12 @@ flagged as an error.
72
72
e.g. the :py:func:`pow` builtin returns ``Any`` (see `typeshed issue 285
73
73
<https://github.com/python/typeshed/issues/285>`_ for the reason).
74
74
75
-
- **:py:meth:`__init__ <object.__init__>` method has no annotated
75
+
- **:py:meth:`__init__ <object.__init__>` method has no annotated
76
76
arguments or return type annotation.** :py:meth:`__init__ <object.__init__>`
77
-
is considered fully-annotated **if at least one argument is annotated**,
77
+
is considered fully-annotated **if at least one argument is annotated**,
78
78
while mypy will infer the return type as ``None``.
79
79
The implication is that, for a :py:meth:`__init__ <object.__init__>` method
80
-
that has no argument, you'll have to explicitly annotate the return type
80
+
that has no argument, you'll have to explicitly annotate the return type
81
81
as ``None`` to type-check this :py:meth:`__init__ <object.__init__>` method:
82
82
83
83
.. code-block:: python
@@ -93,7 +93,7 @@ flagged as an error.
93
93
classB():
94
94
def__init__(self): # No argument is annotated, considered as untyped method
95
95
foo(1) # No error!
96
-
96
+
97
97
classC():
98
98
def__init__(self) -> None: # Must specify return type to type-check
99
99
foo(1) # error: Argument 1 to "foo" has incompatible type "int"; expected "str"
@@ -751,38 +751,60 @@ Mypy has both type aliases and variables with types like ``Type[...]`` and it is
751
751
752
752
deffun1(x: Alias) -> None: ...# This is OK
753
753
deffun2(x: tp) -> None: ...# error: Variable "__main__.tp" is not valid as a type
754
-
754
+
755
755
Incompatible overrides
756
756
------------------------------
757
757
758
-
It's unsafe to override a method with a more specific argument type, as it violates
759
-
the `Liskov substitution principle <https://stackoverflow.com/questions/56860/what-is-an-example-of-the-liskov-substitution-principle>`_. For return types, it's unsafe to override a method with a more general return type.
758
+
It's unsafe to override a method with a more specific argument type,
0 commit comments