Skip to content

Make FixtureFuction type alias instead of TypeVar#14339

Merged
bluetech merged 2 commits intopytest-dev:mainfrom
MarcoGorelli:fixture-function-typevar
Mar 30, 2026
Merged

Make FixtureFuction type alias instead of TypeVar#14339
bluetech merged 2 commits intopytest-dev:mainfrom
MarcoGorelli:fixture-function-typevar

Conversation

@MarcoGorelli
Copy link
Copy Markdown
Contributor

FixtureFunction only appears twice:

def __call__(self, function: FixtureFunction) -> FixtureFunctionDefinition:

pytest/src/_pytest/fixtures.py

Lines 1344 to 1352 in 0e2846f

def fixture(
fixture_function: FixtureFunction | None = None,
*,
scope: _ScopeName | Callable[[str, Config], _ScopeName] = "function",
params: Iterable[object] | None = None,
autouse: bool = False,
ids: Sequence[object | None] | Callable[[Any], object | None] | None = None,
name: str | None = None,
) -> FixtureFunctionMarker | FixtureFunctionDefinition:

Both times, it only appears once in a function signature. Therefore, the TypeVar has no effect

pyright would warn about this too:

  /home/marcogorelli/pytest-dev/src/_pytest/fixtures.py:1241:34 - warning: TypeVar "FixtureFunction" appears only once in generic function signature
    Use "(...) -> object" instead (reportInvalidTypeVarUse)
  /home/marcogorelli/pytest-dev/src/_pytest/fixtures.py:1345:23 - warning: TypeVar "FixtureFunction" appears only once in generic function signature
    Use "(...) -> object" instead (reportInvalidTypeVarUse)

@MarcoGorelli MarcoGorelli force-pushed the fixture-function-typevar branch 4 times, most recently from de87692 to aaf9ab4 Compare March 30, 2026 11:36
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 30, 2026
@MarcoGorelli MarcoGorelli force-pushed the fixture-function-typevar branch from aaf9ab4 to a961889 Compare March 30, 2026 11:41
@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 30, 2026 11:48
@bluetech bluetech added skip news used on prs to opt out of the changelog requirement and removed bot:chronographer:provided (automation) changelog entry is part of PR labels Mar 30, 2026
Copy link
Copy Markdown
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -0,0 +1 @@
Made ``FixtureFunction`` a type alias instead of a type var, as it only ever appears once in any function signature.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not a user-visible change we can skip the changelog, I added skip-news label.

@bluetech bluetech enabled auto-merge (squash) March 30, 2026 17:13
@bluetech bluetech merged commit 3e27786 into pytest-dev:main Mar 30, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants