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 missing docstrings #2762

Merged
merged 22 commits into from
Nov 12, 2023
Merged

Add missing docstrings #2762

merged 22 commits into from
Nov 12, 2023

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Aug 17, 2023

I started trying to write these ... and while I could maybe figure out what the functions are supposed to do it would be lovely if somebody else chipped in with suggestions (@A5rocks? @njsmith?)

This also made me notice that there were some problems in #2753 with open_process and run_process, I noted them here but they should probably be fixed by @TeamSpen210 in a separate PR

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #2762 (218c13d) into master (315a0e8) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2762   +/-   ##
=======================================
  Coverage   99.18%   99.18%           
=======================================
  Files         115      115           
  Lines       17551    17551           
  Branches     3149     3149           
=======================================
  Hits        17408    17408           
  Misses         99       99           
  Partials       44       44           
Files Coverage Δ
src/trio/_core/_io_epoll.py 100.00% <ø> (ø)
src/trio/_core/_io_kqueue.py 87.20% <ø> (ø)
src/trio/_core/_io_windows.py 98.80% <ø> (ø)
src/trio/_socket.py 100.00% <ø> (ø)
src/trio/_subprocess.py 98.27% <ø> (ø)
src/trio/tests.py 100.00% <ø> (ø)

@jakkdl
Copy link
Member Author

jakkdl commented Sep 26, 2023

This is now the only thing remaining for pyright --verifytypes to be run without any issues, and make it possible to remove the endlessly infuriating trio/_tests/verify_types_*.json files. Would love somebody to take a stab at it, if any suggested docstrings are incorrect somebody will probably come along and correct them in a review anyhow.

@jakkdl jakkdl marked this pull request as ready for review October 9, 2023 14:42
@jakkdl
Copy link
Member Author

jakkdl commented Oct 9, 2023

  • need to check if docstrings being undefined when TYPE_CHECKING==True is a problem for any tools.

    • especially for the overload/non-overload diff
    • @TeamSpen210 why does run_process and open_process have @overload on unix but not windows?
  • I had to modify trio/_tools/gen_exports because I was getting warnings:

Warnings when running ruff:
warning: Selection of nursery rule `E225` without the `--preview` flag is deprecated.
warning: Selection of nursery rule `E251` without the `--preview` flag is deprecated.
warning: Selection of nursery rule `E113` without the `--preview` flag is deprecated.
  • and my change broke the gen_exports ruff test. @CoolCat467:
    1. why are we getting that warning (is something weirdly configured?)
    2. result.returncode != 0 does not trigger for some reason, which I fail to reproduce in my shell where bad input to python -m ruff gives $? == 1 np.
  • pre-commit.ci is failing ... and ruff is saying there are 7 problems, but not saying what they are. @CoolCat467 something needs to be changed here
    • it's also weird that pre-commit is passing on my local machine, but failing in CI.

@jakkdl
Copy link
Member Author

jakkdl commented Oct 9, 2023

@njsmith (and anybody else even remotely familiar with #26, #52 or the docstrings in question):

  • I copied docstrings from reference-lowlevel.rst, which was quite straightforwardly the right thing to do for wait_readable, wait_writable, and notify_closing.
  • Less obvious what to do with current_kqueue and friends from Windows: improve usability for low-level IOCP operations #26 and Windows event notification #52, ended up just coping the disclaimer.
  • for some reason write_overlapped and readinto_overlapped was missing entirely from the documentation. I tentatively added them where I'm guessing they should be, if anywhere.

@CoolCat467
Copy link
Member

CoolCat467 commented Oct 10, 2023

why are we getting that warning (is something weirdly configured?)

I think this might be because of differences in the installed version of ruff and the pre-commit ruff hook version, not completely sure to be honest though. At least for me, I always have to run the gen_exports script with python3.11 instead of just running it directly, because my system defaults to python3.9, and the version of packages used in the different python installations is different. Not sure if this applies but I thought I'd mention it.

pre-commit.ci is failing ... and ruff is saying there are 7 problems, but not saying what they are. @CoolCat467 something needs to be changed here

This is because it's attempting to autofix the errors, and right now the config says it doesn't need to comment about what fixes it applies.
--fix-only says:

Fix any fixable lint violations, but don't report on leftover violations. Implies --fix.

So I think the "leftover violations" are the warnings, or maybe we need to specifically say --no-preview

@jakkdl
Copy link
Member Author

jakkdl commented Oct 10, 2023

why are we getting that warning (is something weirdly configured?)

I think this might be because of differences in the installed version of ruff and the pre-commit ruff hook version, not completely sure to be honest though. At least for me, I always have to run the gen_exports script with python3.11 instead of just running it directly, because my system defaults to python3.9, and the version of packages used in the different python installations is different. Not sure if this applies but I thought I'd mention it.

Ah shit, this is my bad. I had a ruff.toml lying around from when I was running ruff locally myself before it was added to pyproject.toml.

pre-commit.ci is failing ... and ruff is saying there are 7 problems, but not saying what they are. @CoolCat467 something needs to be changed here

This is because it's attempting to autofix the errors, and right now the config says it doesn't need to comment about what fixes it applies. --fix-only says:

Fix any fixable lint violations, but don't report on leftover violations. Implies --fix.

So I think the "leftover violations" are the warnings, or maybe we need to specifically say --no-preview

Yeah, it's autofixing instead of reporting the errors but we've disabled autofix in the pre-commit CI and it's failing because files are getting changed. So we either need to disable autofix for ruff when it's run through pre-commit, or for pre-commit to display the changes to the files that caused it to fail.

Re: "@CoolCat467
Success should still be false for warnings"
my change was specifically to not have it fail when giving warnings, but given I've resolved that issue we can probably revert to what the file was like originally and have if result.returncode != 0 or result.stderr:. Though it might be more robust to return return_value, stdout, stderr, the tool itself will ignore any warnings on stderr and only fail if return value is non-zero, and the fail test will assert that return value is non-zero.
This is probably a better fit in a separate PR though, and in here I can revert all changes to [test_]gen_exports.

@TeamSpen210
Copy link
Contributor

TeamSpen210 commented Oct 10, 2023

I think I got the overloads from the trio_typing stubs. The difference is that on Linux/Mac, you can pass a string command only with shell=True, while on Windows you can pass either a string or list of strings regardless of the option. You can't use a single overload for a function, so I had to do the _open_process business. Looking at the typeshed stubs they don't make this distinction for Popen etc, maybe we should too and just simplify the mess.

@jakkdl
Copy link
Member Author

jakkdl commented Oct 10, 2023

I think I got the overloads from the trio_typing stubs. The difference is that on Linux/Mac, you can pass a string command only with shell=True, while on Windows you can pass either a string or list of strings regardless of the option. You can't use a single overload for a function, so I had to do the _open_process business. Looking at the typeshed stubs they don't make this distinction for Popen etc, maybe we should too and just simplify the mess.

Simplifying the mess sounds like a big win to me, cause this is indeed really really messy

@jakkdl jakkdl changed the title [WIP] Add missing docstrings Add missing docstrings Oct 25, 2023
Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Looks great to me - thanks, @jakkdl!

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.

I think that for the information we have these look great

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.

General formatting things, content looks fine.

Comment on lines 354 to 357
"""Call this before closing a file descriptor (on Unix) or socket (on
Windows). This will cause any `wait_readable` or `wait_writable`
calls on the given object to immediately wake up and raise
`~trio.ClosedResourceError`.
Copy link
Contributor

Choose a reason for hiding this comment

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

First line should be a description but not exactly sure what would work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Notify waiters of the given object that it will be closed.

works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah

Comment on lines 771 to 774
"""Call this before closing a file descriptor (on Unix) or socket (on
Windows). This will cause any `wait_readable` or `wait_writable`
calls on the given object to immediately wake up and raise
`~trio.ClosedResourceError`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also missing summary.

Comment on lines 863 to 865
Raises:
OSError: if the process spawning fails, for example because the
specified command could not be found.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this docstring format correct? You use the plain sphinx format elsewhere in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a copy-paste of the docstring at line 346 for _open_process - but maybe that one is incorrectly formatted? Or all the other ones I copy-pasted from the docs are?

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH as long as sphinx renders this fine then whatever. And it does seem to.

Comment on lines 1061 to 1070
Raises:
UnicodeError: if ``stdin`` is specified as a Unicode string, rather
than bytes
ValueError: if multiple redirections are specified for the same
stream, e.g., both ``capture_stdout=True`` and
``stdout=subprocess.DEVNULL``
subprocess.CalledProcessError: if ``check=False`` is not passed
and the process exits with a nonzero exit status
OSError: if an error is encountered starting or communicating with
the process
Copy link
Contributor

Choose a reason for hiding this comment

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

Again note about docstring format

Copy link
Member Author

Choose a reason for hiding this comment

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

same thing - copypasted from run_process earlier in the file. (and yes duplicate docstrings is incredibly ugly and bad... but I don't know how to improve @TeamSpen210's magic to avoid needing to and have it work both on runtime, in static analysis, and on all platforms.)

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH sphinx renders this fine so whatever.

@jakkdl jakkdl requested a review from A5rocks November 11, 2023 12:06
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.

Looks fine, if things don't like multiple docstring formats then we can fix them then. Not worth the time ATM I think.

(also the summary looks fine, so maybe add that before merging ^^ -- not sure if you already did but the comments aren't resolved so IDK)

@jakkdl jakkdl merged commit 44f7f2d into python-trio:master Nov 12, 2023
@jakkdl
Copy link
Member Author

jakkdl commented Nov 12, 2023

Sorry yeah, I added them :)

Time to get rid of the jsons!! 🚀

@jakkdl jakkdl deleted the missing_docstrings branch November 12, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants