Skip to content

capture: improve typing #10680

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 6 commits into from
Jan 23, 2023
Merged

capture: improve typing #10680

merged 6 commits into from
Jan 23, 2023

Conversation

bluetech
Copy link
Member

I'm looking at improving the capture plugin again, but first I thought I'd finish the typing. Adds some verbosity but needed to "capture" the current usage.

Might be easier to review commit by commit.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

LGTM!

Just have to adapt some of the unsupported features for Python 3.8/3.7. 👍

@bluetech bluetech force-pushed the capture-typing branch 2 times, most recently from d1f1e4f to 234103b Compare January 21, 2023 20:50
@bluetech bluetech closed this Jan 23, 2023
@bluetech bluetech deleted the capture-typing branch January 23, 2023 12:01
@bluetech bluetech restored the capture-typing branch January 23, 2023 12:01
@bluetech bluetech reopened this Jan 23, 2023
Have `DontReadFromInput` inherit from `TextIO`, ensuring it's fully
compatible with `sys.stdin` (which has type `TextIO`).
Instead of `SysCapture`/`FDCapture` inheriting from
`SysCaptureBinary`/`FDCaptureBinary`, have both inherit from a common
`SysCaptureBase`/`FDCaptureBase`. This fixes a Liskov substitution
violation.
Previously, the any `captureclass` arguments were Any. We need to
introduce another common base class to fix this.
This is OK in mypy, but doesn't hurt to fix.
@bluetech
Copy link
Member Author

@nicoddemus Thanks for the notes, fixed. Also fixed the coverage.

@bluetech bluetech merged commit 0289313 into pytest-dev:main Jan 23, 2023
@bluetech bluetech deleted the capture-typing branch January 23, 2023 12:45
@hroncok
Copy link
Member

hroncok commented Apr 11, 2023

Is it possible that this broke some assumptions? Namely, I see this error in click:

==================================== ERRORS ====================================
_____________________ ERROR at teardown of test_bytes_args _____________________
/usr/lib/python3.11/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.11/site-packages/_pytest/runner.py:262: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
/usr/lib/python3.11/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
/usr/lib/python3.11/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/usr/lib/python3.11/site-packages/_pytest/runner.py:182: in pytest_runtest_teardown
    item.session._setupstate.teardown_exact(nextitem)
/usr/lib/python3.11/site-packages/_pytest/runner.py:537: in teardown_exact
    raise exceptions[0]
/usr/lib/python3.11/site-packages/_pytest/runner.py:526: in teardown_exact
    fin()
/usr/lib/python3.11/site-packages/_pytest/fixtures.py:686: in <lambda>
    subrequest.node.addfinalizer(lambda: fixturedef.finish(request=subrequest))
/usr/lib/python3.11/site-packages/_pytest/fixtures.py:1038: in finish
    raise exc
/usr/lib/python3.11/site-packages/_pytest/fixtures.py:1031: in finish
    func()
/usr/lib/python3.11/site-packages/_pytest/fixtures.py:918: in _teardown_yield_fixture
    next(it)
/usr/lib/python3.11/site-packages/_pytest/monkeypatch.py:55: in monkeypatch
    mpatch.undo()
/usr/lib/python3.11/site-packages/_pytest/monkeypatch.py:397: in undo
    setattr(obj, name, value)
E   AttributeError: property 'encoding' of 'DontReadFromInput' object has no setter
=================================== FAILURES ===================================
_______________________________ test_bytes_args ________________________________
tests/test_arguments.py:89: in test_bytes_args
    monkeypatch.setattr(sys.stdin, "encoding", "utf-8")
E   AttributeError: property 'encoding' of 'DontReadFromInput' object has no setter
=========================== short test summary info ============================
FAILED tests/test_arguments.py::test_bytes_args - AttributeError: property 'e...
ERROR tests/test_arguments.py::test_bytes_args - AttributeError: property 'en...

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.

3 participants