-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
DOC403 behaviour with yielding none #13001
Comments
This seems like a bug. An empty ruff/crates/ruff_linter/src/rules/pydoclint/rules/check_docstring.rs Lines 638 to 644 in 4d0d3b0
@augustelalande just checking in to see if there's a specific reason behind this otherwise we can remove the |
I did this on purpose because IMO the yields section should document the yielded value not, the function behaviour associated with the yield. Similar to return None, not needing documentation. The yield "behaviour" could be documented in the docstring summary. But if people feel strongly the other way, feel free to change the behaviour. |
@augustelalande to be fair I do agree with your logic. I only raised this due to conflicting behaviour with numpydoc's validation tool. |
Yeah, that makes sense.
@jonyscathe That might be useful, thanks |
The numpydoc people do believe that the yield should be documented even if it is none, as it is not really the same thing as returning none (the yield is still doing something). They also have the example that something like:
is inherently different to:
And should be documented as such in the Yields section (10 implicit None's via a generator vs 1). |
... and just to bring the discussion over here to save some a click, I suggested:
It seems natural to put this in a |
@jonyscathe @larsoner Thanks for confirming! I think it makes sense to update the behavior. All we need is to remove the It seems that |
Is the suggestion to report docstring-missing-yields (DOC402) on @pytest.fixture
def db_setup() -> Generator[None, None, None]:
"""
Add test user.
"""
database = Database('my_database_url')
with database.create_session() as session:
session.execute(insert(database.Users, [{'id': 1, 'name': 'Bob'}
yield
with database.create_session() as session:
session.execute(delete(database.Users).where(database.Users.id == 1234) as well? If it is unclear whether implicit yield If we want both DOC403 and DOC402 make exceptions for implicit yields (that is to say, count them in one and ignore in them in the other), then it is more than a one-line code change. Possibly related to #13062 |
"DOC403 ", "numpydoc", "yields"
ruff /path/to/file.py --fix
), ideally including the--isolated
flag.ruff /path/to/file.py --fix
pyproject.toml
).ruff --version
).ruff 0.6.1
The above code snippet results in a DOC403 Docstring has a "Yields" section but the function doesn't yield anything.
If the yields section is removed from the docstring then numpydoc-validation reports:
I understand that it is debatable about what the docstring should be a for a yield statement that yields None, but I think ruff should probably match the numpydoc-validator tool in this case.
The text was updated successfully, but these errors were encountered: