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 io_windows #2761

Merged
merged 28 commits into from
Sep 25, 2023
Merged

add types to io_windows #2761

merged 28 commits into from
Sep 25, 2023

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Aug 17, 2023

I hit a wall implementing this and I found it a hassle not being on windows, so would be lovely if anybody would take it over

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #2761 (bc9cbb6) into master (1e8327b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2761   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files         115      115           
  Lines       17102    17117   +15     
  Branches     3079     3079           
=======================================
+ Hits        16927    16942   +15     
  Misses        121      121           
  Partials       54       54           
Files Changed Coverage Δ
trio/_tools/gen_exports.py 100.00% <ø> (ø)
trio/_core/_io_common.py 100.00% <100.00%> (ø)
trio/_core/_io_windows.py 98.80% <100.00%> (+0.02%) ⬆️
trio/_core/_tests/test_windows.py 100.00% <100.00%> (ø)
trio/_core/_windows_cffi.py 100.00% <100.00%> (ø)
trio/_subprocess_platform/waitid.py 70.73% <100.00%> (ø)
trio/_wait_for_object.py 100.00% <100.00%> (ø)

@A5rocks
Copy link
Contributor

A5rocks commented Aug 24, 2023

I can maybe try to work on this (as I mainly use Windows) -- I would use GitHub's assignment thing that I remember it having but I can't find the buttons on mobile :(

@TeamSpen210
Copy link
Contributor

Pushed an attempt to type the CFFI parts, not sure if we want to go that route (or just leave them dynamic)? With a bunch of NewType we could check all the types.

@A5rocks A5rocks marked this pull request as ready for review August 26, 2023 01:44
@A5rocks A5rocks changed the title [ORPHAN] add types to io_windows add types to io_windows Aug 26, 2023
@A5rocks A5rocks added the typing Adding static types to trio's interface label Aug 26, 2023
@A5rocks
Copy link
Contributor

A5rocks commented Aug 26, 2023

I don't understand the pypy failure but that does seem to be non-transient

@A5rocks
Copy link
Contributor

A5rocks commented Aug 26, 2023

Looks like pypy on Windows is broken on master too, but since 0c108f9 so I think it's an upstream issue.



class WindowsIOManager:
def __init__(self):
def __init__(self) -> None:
# If this method raises an exception, then __del__ could run on a
# half-initialized object. So we initialize everything that __del__
# touches to safe values up front, before we do anything that can
# fail.
self._iocp = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Since iocp can only be None if __init__ fails (so in __del__), it might be better to just cast/type-ignore the none assignment, so we avoid asserts everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could also add a self._is_initialized variable that's initially set to False, and set to True after self._iocp is initialized.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since iocp can only be None if __init__ fails (so in __del__), it might be better to just cast/type-ignore the none assignment, so we avoid asserts everywhere.

FWIW it can also be None after .close but IDK if the object still exists then.

trio/_core/_io_windows.py Outdated Show resolved Hide resolved
trio/_core/_windows_cffi.py Outdated Show resolved Hide resolved
trio/_core/_generated_io_windows.py Outdated Show resolved Hide resolved
@jakkdl
Copy link
Member Author

jakkdl commented Aug 29, 2023

Ah, thought there was something wrong with #2750 but it's rather that this PR is pushing unformatted code - i.e. need to rerun gen_exports

@jakkdl
Copy link
Member Author

jakkdl commented Aug 30, 2023

I can't approve a PR I created, but LGTM ✔️

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

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

Looks good to me

@A5rocks A5rocks requested a review from TeamSpen210 September 12, 2023 21:10
Copy link
Contributor

@TeamSpen210 TeamSpen210 left a comment

Choose a reason for hiding this comment

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

Looks good, only have a few quibbles.

Pointer: object


class _Overlapped(Protocol):
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to just make this public, if it's being imported elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I'm not sure how to think about Protocol publicness as they are meant to be purely structural and any use of them could be replaced with a copy-pasted copy

async def wait_overlapped(self, handle, lpOverlapped):
handle = _handle(handle)
async def wait_overlapped(
self, handle_: int | CData, lpOverlapped: CData | int
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of casting to/from CData, maybe we should type it as our Overlapped / Handle types, so this can be statically checked? Or just add those to the union alongside CData, to be more loose.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would push out lpOverlapped casting to a boundary... but looking at the code, this is public :(

The type casting can probably be improved though.

trio/_core/_windows_cffi.py Show resolved Hide resolved
from typing import TYPE_CHECKING, ContextManager

if TYPE_CHECKING:
from .._file_io import _HasFileNo
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems iffy to be importing a private name from a different module, might want to make this also public.

@A5rocks
Copy link
Contributor

A5rocks commented Sep 22, 2023

@TeamSpen210 just wanted to make sure you saw my responses and think it's still fine!

(mainly about Protocol public-ness...)

@TeamSpen210
Copy link
Contributor

That does make sense, it’s of course easier to make something public than the reverse.

@A5rocks A5rocks merged commit 4ee5413 into python-trio:master Sep 25, 2023
28 checks passed
@jakkdl jakkdl deleted the type_io_windows branch September 25, 2023 16:14
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.

4 participants