Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-127443: add tool for lintingDoc/data/refcounts.dat
#127476
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
picnixz wants to merge32 commits intopython:mainChoose a base branch frompicnixz:tools/refcounts/lint-127443
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes from1 commit
Commits
Show all changes
32 commits Select commitHold shift + click to select a range
183388f
Add tool for linting `Doc/data/refcounts.dat`
picnixz9c2a109
use single-quotes
picnixz6c1a19e
add default paths
picnixz419197b
use NamedTuple whenever possible
picnixz58ffbeb
address Peter's review
picnixz9a46f10
fix typos
picnixz8372de6
address Alex's review
picnixz4bcf719
format using a mix of black/ruff/picnixz format
picnixz841a4b1
rename STEALS -> STEAL
picnixz970cbc7
detect more ref. count manageable objects
picnixz4558483
add `lineno` to RETURN values and use kw-only
picnixzb8f6090
use helper for C identifier detection
picnixzdb9b6e6
`RefType` -> `RefEffect`
picnixz480f500
improve `ParserReporter`
picnixz9814dd7
disallow stolen ref in return values
picnixz82766b3
add doc
picnixze7a7a10
fix workflow
picnixzf64a23d
update pre-commit hook
picnixz2eb541f
fix some typos
picnixzcf42e03
restrict the ruff rules
picnixzeb893d0
add ruff docstrings rules
picnixzdbe29a6
address Peter's review
picnixz658e332
update some variable names
picnixz5660ffe
add TODO messages
picnixzafceff0
RefEffect -> Effect
picnixzd173d7a
extract checking logic into smaller functions
picnixz0edd489
add --strict errors mode
picnixza3becf0
additional stealing effects
picnixz3ac1ff1
Merge remote-tracking branch 'upstream/main' into tools/refcounts/lin…
picnixzbaf2474
address Hugo's review
picnixz549ba49
remove TODO symbols for now (we don't want yet to change the Sphinx e…
picnixzc708a4c
address Alex's review
picnixzFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
address Peter's review
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit58ffbeb5851d27eb0c2168ed6cba103b5226996b
There are no files selected for viewing
28 changes: 16 additions & 12 deletionsTools/refcounts/lint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,14 +9,14 @@ | ||
from dataclasses import dataclass, field | ||
from enum import auto as _auto, Enum | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, LiteralString | ||
if TYPE_CHECKING: | ||
from collections.abc import Callable,Final,Iterable, Mapping | ||
ROOT = Path(__file__).parent.parent.parent.resolve() | ||
DEFAULT_REFCOUNT_DAT_PATH:Final[str] = str(ROOT / 'Doc/data/refcounts.dat') | ||
DEFAULT_STABLE_ABI_TOML_PATH:Final[str] = str(ROOT / 'Misc/stable_abi.toml') | ||
C_ELLIPSIS: LiteralString = '...' | ||
@@ -62,7 +62,8 @@ class RefType(Enum): | ||
STEALS = _auto() | ||
NULL = _auto() # for return values only | ||
@dataclass(slots=True, frozen=True) | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
class LineInfo: | ||
func: str | ||
ctype: str | None | ||
name: str | None | ||
@@ -79,12 +80,14 @@ class LineInfo(NamedTuple): | ||
strip_name: bool | ||
strip_reftype: bool | ||
@dataclass(slots=True, frozen=True) | ||
class Return: | ||
ctype: str | None | ||
reftype: RefType | None | ||
comment: str | ||
@dataclass(slots=True, frozen=True) | ||
class Param: | ||
name: str | ||
lineno: int | ||
@@ -99,7 +102,8 @@ class Signature: | ||
rparam: Return | ||
params: dict[str, Param] = field(default_factory=dict) | ||
@dataclass(slots=True, frozen=True) | ||
class FileView: | ||
signatures: Mapping[str, Signature] | ||
incomplete: frozenset[str] | ||
@@ -255,7 +259,7 @@ def check(view: FileView) -> None: | ||
def check_structure(view: FileView, stable_abi_file: str) -> None: | ||
print(f"Stable ABI file: {stable_abi_file}") | ||
print() | ||
stable_abi_str = Path(stable_abi_file).read_text(encoding='utf-8') | ||
stable_abi = tomllib.loads(stable_abi_str) | ||
expect = stable_abi['function'].keys() | ||
# check if there are missing entries (those marked as "TODO" are ignored) | ||
@@ -265,7 +269,7 @@ def check_structure(view: FileView, stable_abi_file: str) -> None: | ||
for name in sorted(missing): | ||
print(name) | ||
_STABLE_ABI_FILE_SENTINEL: Final = object() | ||
def _create_parser() -> ArgumentParser: | ||
parser = ArgumentParser( | ||
@@ -277,15 +281,15 @@ def _create_parser() -> ArgumentParser: | ||
parser.add_argument('file', nargs='?', default=DEFAULT_REFCOUNT_DAT_PATH, | ||
help='the refcounts.dat file to check ' | ||
'(default: %(default)s)') | ||
parser.add_argument('--abi', nargs='?', default=_STABLE_ABI_FILE_SENTINEL, | ||
help='check against the given stable_abi.toml file ' | ||
'(default: %s)' % DEFAULT_STABLE_ABI_TOML_PATH) | ||
return parser | ||
def main() -> None: | ||
parser = _create_parser() | ||
args = parser.parse_args() | ||
lines = Path(args.file).read_text(encoding='utf-8').splitlines() | ||
print(' PARSING '.center(80, '-')) | ||
view = parse(lines) | ||
print(' CHECKING '.center(80, '-')) | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.