Need plugin hooks for functions/methods
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
For some frameworks like pytest it would be useful to have a plugin that works with functions.
Currently mypy has decorator hook for classes.
Some ideas for possible hooks:
- update function namespace to inject some names
- modify function signature
- generate function signature (types)
For example pytest has the following fixture
from pathlib import Path
@pytest.fixture
def db_path(tmp_path: Path) -> Path:
return tmp_path / 'test.db'
The fixture is used by name:
def test_a(db_path) -> None:
....
db_path argument here is a calucated the result of db_path() fixture call.
It is bound by parameter name which is the same as the fixture name.
Adding a type to db_path argument is tedious, especially if a fixture returns some complex type like Callable[[str, int], Awaitable[web.Response]].
Technically all needed information can be extracted from fixture definition if the definition is type annotated.
A plugin for pytest would be awesome but as @ilevkivskyi said mypy needs a new hook to support it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing mypy's existing decorator hook for classes and the plugin API concepts described in the issue. Determine how function namespace injection, signature modification, and generated signatures should work for pytest-style fixtures, then define tests that show fixture parameters receive the inferred return type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100