Skip to content

static typecheck error in pytest-mypy-plugins pipeline: pytest 8.3.0 renamed _TracebackStyle to TracebackStyle #158

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

Closed
mjpieters opened this issue Dec 20, 2024 · 0 comments · Fixed by #159

Comments

@mjpieters
Copy link
Contributor

Pytest renamed _pytest._code.code._TracebackStyle to _pytest._code.code.TracebackStyle in version 8.3.0, which means that the mypy checks in pipelines here now fail with:

pytest_mypy_plugins/item.py:22: error: Module "_pytest._code.code" has no attribute "_TracebackStyle"; maybe "TracebackStyle", "TracebackType", or "TracebackEntry"? [attr-defined]

You can't work around this renaming in static type checks (there is no recognised syntax for a type checker to change an import statically), so the only work-around is to not import that name until pytest 8.3.0 is the minimum requirement for this project.

I'd instead just define it locally:

if TYPE_CHECKING:
    # pytest 8.3.0 renamed _TracebackStyle to TracebackStyle, but there is no syntax
    # to assert what version you have using static conditions, so it has to be
    # manually re-defined here. Once minimum supported pytest version is >= 8.3.0,
    # the following can be replaced with `from _pytest._code.code import TracebackStyle`
    TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"]

(I renamed _TracebackStyle to TracebackStyle to make it easier to switch later).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant