Skip to content

Commit c667789

Browse files
authored
Improve yaml/constructor.pyi types
When updating mypy to 1.11.0 in typeddjango/django-stubs#2269 I noticed this: ``` ______________________________ import_all_modules ______________________________ /home/runner/work/django-stubs/django-stubs/tests/typecheck/test_import_all.yml:2: E pytest_mypy_plugins.utils.TypecheckAssertionError: Output is not expected: E Actual: E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:87: error: Signature of "find_python_module" incompatible with supertype "FullConstructor" [override] (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:87: note: Superclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:87: note: def find_python_module(self, name: Any, mark: Any, unsafe: Any = ...) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:87: note: Subclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:87: note: def find_python_module(self, name: Any, mark: Any) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:88: error: Signature of "find_python_name" incompatible with supertype "FullConstructor" [override] (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:88: note: Superclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:88: note: def find_python_name(self, name: Any, mark: Any, unsafe: Any = ...) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:88: note: Subclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:88: note: def find_python_name(self, name: Any, mark: Any) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:89: error: Signature of "make_python_instance" incompatible with supertype "FullConstructor" [override] (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:89: note: Superclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:89: note: def make_python_instance(self, suffix: Any, node: Any, args: Any = ..., kwds: Any = ..., newobj: Any = ..., unsafe: Any = ...) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:89: note: Subclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:89: note: def make_python_instance(self, suffix: Any, node: Any, args: Any = ..., kwds: Any = ..., newobj: Any = ...) -> Any (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:90: error: Signature of "set_python_instance_state" incompatible with supertype "FullConstructor" [override] (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:90: note: Superclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:90: note: def set_python_instance_state(self, instance: Any, state: Any, unsafe: bool = ...) -> None (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:90: note: Subclass: (diff) E ../../opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/yaml-stubs/constructor.pyi:90: note: def set_python_instance_state(self, instance: Any, state: Any) -> Any (diff) E Expected: E (empty) =========================== short test summary info ============================ ``` This happens because `UnsafeConstructor` has unsafe method overrides and new mypy detects this. So, I added just some simple annotations so it can detect it now as well.
1 parent 128d8eb commit c667789

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

stubs/PyYAML/yaml/constructor.pyi

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,21 @@ class FullConstructor(SafeConstructor):
7373
def construct_python_long(self, node): ...
7474
def construct_python_complex(self, node): ...
7575
def construct_python_tuple(self, node): ...
76-
def find_python_module(self, name, mark, unsafe=False): ...
77-
def find_python_name(self, name, mark, unsafe=False): ...
76+
def find_python_module(self, name: str, mark, unsafe: bool = False): ...
77+
def find_python_name(self, name: str, mark, unsafe: bool = False): ...
7878
def construct_python_name(self, suffix, node): ...
7979
def construct_python_module(self, suffix, node): ...
80-
def make_python_instance(self, suffix, node, args=None, kwds=None, newobj=False, unsafe=False): ...
81-
def set_python_instance_state(self, instance, state, unsafe: bool = False) -> None: ...
80+
def make_python_instance(self, suffix, node, args=None, kwds=None, newobj: bool = False, unsafe: bool = False): ...
81+
def set_python_instance_state(self, instance: Any, state, unsafe: bool = False) -> None: ...
8282
def construct_python_object(self, suffix, node): ...
8383
def construct_python_object_apply(self, suffix, node, newobj=False): ...
8484
def construct_python_object_new(self, suffix, node): ...
8585

8686
class UnsafeConstructor(FullConstructor):
87-
def find_python_module(self, name, mark): ...
88-
def find_python_name(self, name, mark): ...
89-
def make_python_instance(self, suffix, node, args=None, kwds=None, newobj=False): ...
90-
def set_python_instance_state(self, instance, state): ...
87+
def find_python_module(self, name: str, mark): ...
88+
def find_python_name(self, name: str, mark): ...
89+
def make_python_instance(self, suffix: str, node, args=None, kwds=None, newobj: bool = False): ...
90+
def set_python_instance_state(self, instance: Any, state): ...
9191

9292
class Constructor(SafeConstructor):
9393
def construct_python_str(self, node): ...

0 commit comments

Comments
 (0)