Skip to content
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

Add types to test_io, test_run, various other fixes #2773

Merged
merged 18 commits into from
Aug 30, 2023

Conversation

TeamSpen210
Copy link
Contributor

@TeamSpen210 TeamSpen210 commented Aug 24, 2023

Adds types for two tests, and implements some TODOs.

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #2773 (c02a01e) into master (e9975aa) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2773      +/-   ##
==========================================
- Coverage   98.94%   98.94%   -0.01%     
==========================================
  Files         113      113              
  Lines       16870    16852      -18     
  Branches     3041     3032       -9     
==========================================
- Hits        16692    16674      -18     
  Misses        123      123              
  Partials       55       55              
Files Changed Coverage Δ
trio/_core/_run.py 99.43% <ø> (-0.02%) ⬇️
trio/_core/_tests/test_io.py 100.00% <100.00%> (ø)
trio/_core/_tests/test_run.py 100.00% <100.00%> (ø)
trio/_highlevel_generic.py 100.00% <100.00%> (ø)
trio/_sync.py 100.00% <100.00%> (ø)

"withKnownType": 682,
"withKnownType": 680,
Copy link
Member

Choose a reason for hiding this comment

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

if checking manually (I realize now I removed generating full_output.json feel free to add that back if it helps), what's the removed symbols?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be the nursery.start() protocol, and its __call__ method.

Copy link
Member

Choose a reason for hiding this comment

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

👍
We might want to keep a version of these json files around in the end after all, though just as the list of symbols. Kinda similar to what test_exports is doing but not quite. I'm not sure if dropping private symbols is ever really a problem, but could be good to keep track of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, as long as everything works (= tests pass). If it's private, by definition it can change whenever we want.

Copy link
Member

Choose a reason for hiding this comment

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

Well, main reason would be checking the public types - the private types mostly just incidental but I don't think it hurts (at least if the updating of the file can be automated in pre-commit or so)

@A5rocks A5rocks added the typing Adding static types to trio's interface label Aug 26, 2023
Copy link
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

My eyes glazed over reading test_run, that file is insanely long! The rest looks good though

Comment on lines -1176 to +1170
self, async_fn: _NurseryStartFunc[StatusT], *args: object, name: object = None
self,
async_fn: Callable[..., Awaitable[object]],
*args: object,
name: object = None,
Copy link
Member

Choose a reason for hiding this comment

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

So this drops the check for it accepting a task_status parameter. If that's planned to be added back with ParamSpec/TypeVarTuple it probably warrants a #TODO explicitly mentioning that. Or is there a reason for dropping it?

Copy link
Contributor Author

@TeamSpen210 TeamSpen210 Aug 26, 2023

Choose a reason for hiding this comment

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

Yeah it needs TypeVarTuple. That protocol would only match callables that actually themselves use *args, which is not ideal. I got myself a little mixed up when trying to do it.

"withKnownType": 682,
"withKnownType": 680,
Copy link
Member

Choose a reason for hiding this comment

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

Well, main reason would be checking the public types - the private types mostly just incidental but I don't think it hurts (at least if the updating of the file can be automated in pre-commit or so)

Copy link
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

Looks ready to be merged

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

A couple nitpicks, a couple questions. Nothing that seems like it absolutely needs to be fixed but maybe one of the questions shows something is unnecessary?

trio/_core/_tests/test_io.py Show resolved Hide resolved
nonlocal t1, t2
t1 = _core.current_task()
print("child1 start")
x = await sleep_forever()
print("child1 woke")
assert x == 0
print("child1 rescheduling t2")
_core.reschedule(t2, outcome.Error(ValueError()))
_core.reschedule(not_none(t2), outcome.Error(ValueError()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put the assert above this call? (similar for the one below)

Just a nitpick though, really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added not_none() to try and distinguish between asserts used to test Trio, and ones used to indicate what should be happening here. If t2 never gets set, there's either something wrong with the test or I guess Trio's core internals.

async def test_root_task():
root = _core.current_root_task()
async def test_root_task() -> None:
root = not_none(_core.current_root_task())
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above comment.

I'm not commenting on test_current_task I feel like getting a None there would be less an issue with the current_task() but idk, maybe that too?

trio/_core/_tests/test_run.py Show resolved Hide resolved
trio/_core/_tests/test_run.py Outdated Show resolved Hide resolved
trio/_core/_tests/test_run.py Outdated Show resolved Hide resolved
trio/_core/_tests/test_run.py Outdated Show resolved Hide resolved
Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

LGTM!

@TeamSpen210 TeamSpen210 merged commit e97bcb6 into python-trio:master Aug 30, 2023
@TeamSpen210 TeamSpen210 deleted the type-misc-tests branch August 30, 2023 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Adding static types to trio's interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants