Skip to content

Commit d6154ce

Browse files
committed
Review findings
1 parent 8f9607e commit d6154ce

5 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎conformance/results/mypy/protocols_generic.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protocols_generic.py:74: error: Incompatible types in assignment (expression has
1818
protocols_generic.py:75: error: Incompatible types in assignment (expression has type "AttrProto[float]", variable has type "AttrProto[int]") [assignment]
1919
protocols_generic.py:133: error: Incompatible types in assignment (expression has type "InvalidParentProperty", variable has type "HasParentProperty") [assignment]
2020
protocols_generic.py:133: note: Following member(s) of "InvalidParentProperty" have conflicts:
21-
protocols_generic.py:133: note: parent: expected "InvalidParentProperty", got "int"
21+
protocols_generic.py:133: note: parent: expected "InvalidParentProperty", got "HasParentProperty"
2222
protocols_generic.py:153: error: Incompatible types in assignment (expression has type "InvalidHasMethod", variable has type "HasMethod") [assignment]
2323
protocols_generic.py:153: note: Following member(s) of "InvalidHasMethod" have conflicts:
2424
protocols_generic.py:153: note: Expected:

‎conformance/results/pyright/protocols_generic.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ protocols_generic.py:75:26 - error: Type "AttrProto[float]" is not assignable to
2828
protocols_generic.py:133:26 - error: Type "InvalidParentProperty" is not assignable to declared type "HasParentProperty"
2929
  "InvalidParentProperty" is incompatible with protocol "HasParentProperty"
3030
    "parent" is an incompatible type
31-
      Type "() -> int" is not assignable to type "() -> InvalidParentProperty"
31+
      Type "() -> HasParentProperty" is not assignable to type "() -> InvalidParentProperty"
3232
        "HasParentProperty" is not assignable to "InvalidParentProperty"
33-
        Function return type "int" is incompatible with type "InvalidParentProperty"
34-
          "int" is not assignable to "InvalidParentProperty" (reportAssignmentType)
33+
        Function return type "HasParentProperty" is incompatible with type "InvalidParentProperty"
34+
          "HasParentProperty" is not assignable to "InvalidParentProperty" (reportAssignmentType)
3535
protocols_generic.py:153:18 - error: Type "InvalidHasMethod" is not assignable to declared type "HasMethod"
3636
  "InvalidHasMethod" is incompatible with protocol "HasMethod"
3737
    "m" is an incompatible type

‎conformance/results/zuban/protocols_generic.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protocols_generic.py:74: error: Incompatible types in assignment (expression has
1919
protocols_generic.py:75: error: Incompatible types in assignment (expression has type "AttrProto[float]", variable has type "AttrProto[int]") [assignment]
2020
protocols_generic.py:133: error: Incompatible types in assignment (expression has type "InvalidParentProperty", variable has type "HasParentProperty") [assignment]
2121
protocols_generic.py:133: note: Following member(s) of "InvalidParentProperty" have conflicts:
22-
protocols_generic.py:133: note: parent: expected "InvalidParentProperty", got "int"
22+
protocols_generic.py:133: note: parent: expected "InvalidParentProperty", got "HasParentProperty"
2323
protocols_generic.py:153: error: Incompatible types in assignment (expression has type "InvalidHasMethod", variable has type "HasMethod") [assignment]
2424
protocols_generic.py:153: note: Following member(s) of "InvalidHasMethod" have conflicts:
2525
protocols_generic.py:153: note: Expected:

‎conformance/tests/protocols_generic.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def parent(self) -> Self:
125125

126126
class InvalidParentProperty:
127127
@property
128-
def parent(self) -> int:
129-
return 0
128+
def parent(self) -> HasParentProperty:
129+
return ConcreteParentProperty()
130130

131131

132132
hp1: HasParentProperty = ConcreteParentProperty() # OK

‎docs/guides/writing_stubs.rst‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,24 +647,23 @@ No::
647647
def foo(x: X = X()) -> None: ...
648648
def bar(y: str = None) -> None: ...
649649

650-
Do not annotate ``self`` and ``cls`` in method definitions, except when
651-
referencing a type variable.
650+
Do not annotate ``self`` and ``cls`` in method definitions unless an explicit
651+
annotation is needed to constrain or relax the receiver type.
652652

653653
Yes::
654654

655-
_T = TypeVar("_T", bound="Foo")
656-
657655
class Foo:
658656
def bar(self) -> None: ...
659657
@classmethod
660-
def create(cls: type[_T]) -> _T: ...
658+
def create(cls) -> Self: ...
661659

662660
No::
663661

664662
class Foo:
665-
def bar(self: Foo) -> None: ...
663+
def bar1(self: Self) -> None: ...
664+
def bar2(self: Foo) -> None: ...
666665
@classmethod
667-
def baz(cls: type[Foo]) -> int: ...
666+
def create(cls: type[Self]) -> Self: ...
668667

669668
The bodies of functions and methods should consist of only the ellipsis
670669
literal ``...`` on the same line as the closing parenthesis and colon.

0 commit comments

Comments
 (0)