Skip to content

Improve yaml/constructor.pyi types #12404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2024
Merged

Improve yaml/constructor.pyi types #12404

merged 2 commits into from
Jul 23, 2024

Conversation

sobolevn
Copy link
Member

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.

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.
@sobolevn
Copy link
Member Author

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit ce9f32d into main Jul 23, 2024
48 checks passed
@srittau srittau deleted the sobolevn-patch-2 branch July 23, 2024 12:08
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants