`ANN001` and `ANN201` for override methods?
- Dominant language
- Rust
- Stars
- 49.7k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
When overriding a method from a parent class, is it required to define the entire original method signature with its argument and return types? I'm not sure if this is a personal preference thing, but I don't really want to have to redefine or import any non-builtin types if I don't have to (especially for more complex methods) - VS Code IntelliSense seems to pick these up already without any type hints.
Given the following example
`example.py`
```py
"""Example module."""
from singer_sdk.streams.rest import RESTStream
from typing_extensions import override
class MyRESTStream(RESTStream):
"""My RESTStream implementation."""
@override
def prepare_request(self, context, next_page_token):
return super().prepare_request(context, next_page_token)
```
where `RESTStream.prepare_request` is a fully-annotated method...
### Expected
No errors
### Actual
```
example.py:11:9: ANN201 Missing return type annotation for public function `prepare_request`
example.py:11:31: ANN001 Missing type annotation for function argument `context`
example.py:11:40: ANN001 Missing type annotation for function argument `next_page_token`
Found 3 errors.
```
This is the code that fixes the above 3 errors and some others after importing:
`example.py`
```py
"""Example module."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from singer_sdk.streams.rest import RESTStream
from typing_extensions import override
if TYPE_CHECKING:
from requests.models import PreparedRequest
class MyRESTStream(RESTStream):
"""My RESTStream implementation."""
@override
def prepare_request(
self,
context: dict | None,
next_page_token: Any | None,
) -> PreparedRequest:
return super().prepare_request(context, next_page_token)
```
Contributor guide
Research direction
Start with the example.py reproduction and the RESTStream.prepare_request override shown in the issue, then run Ruff with ANN001 and ANN201 to confirm the three diagnostics. Done means an override matching this case no longer produces those errors without requiring duplicated annotations, while existing annotation checks continue to behave correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100