-
Notifications
You must be signed in to change notification settings - Fork 61
Improve behaviour of option -W #933
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
f2d357f
452ff15
0ce62d8
646f7d6
313a6c6
442e201
cf7a904
0c316e7
818cde5
157e8c4
a91a579
7b41478
8037abd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from pathlib import Path | ||
| import sys | ||
| import functools | ||
| import contextvars | ||
| from typing import Any, Type, TypeVar, Tuple, Union, cast, TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -103,3 +104,24 @@ class NewPartialCls(cls): | |
| __class__ = cls | ||
| assert isinstance(NewPartialCls, type) | ||
| return NewPartialCls | ||
|
|
||
| class PydoctorWarning(UserWarning): | ||
| """ | ||
| Base class for all warnings emitted by pydoctor thru the L{warnings} module. | ||
| """ | ||
|
|
||
| _warned = contextvars.ContextVar('warned', default=False) | ||
|
|
||
| def warn(msg: str) -> None: | ||
| """ | ||
| Emit a pydoctor warning message. | ||
| """ | ||
| import warnings | ||
| warnings.warn(msg, category=PydoctorWarning) | ||
| _warned.set(True) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels a little delicate that all warnings emitted by pydoctor need to go through this function for the error status to track. There's nothing beyond familiarity with the codebase to guide future contributions down this path. Could this be made more robust? Perhaps a lint rule could forbid direct use of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don’t have this kind of custom linting in place at the moment. I suppose this can be implemented with a semgrep pattern. But do you have another idea to enforce this ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps flake8-tidy-imports banned-api? I've used it to banish |
||
|
|
||
| def warned() -> bool: | ||
| """ | ||
| Return whether any pydoctor warning has been emitted. | ||
| """ | ||
| return _warned.get() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, a link would be more actionable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, but the chalenge is to provide the right link. And that depends on the current pydoctor version, so this would add more complexity