Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:main
base:main
Choose a base branch
Loading
frompicnixz:tools/refcounts/lint-127443
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`
picnixzDec 1, 2024
9c2a109
use single-quotes
picnixzDec 1, 2024
6c1a19e
add default paths
picnixzDec 1, 2024
419197b
use NamedTuple whenever possible
picnixzDec 1, 2024
58ffbeb
address Peter's review
picnixzDec 1, 2024
9a46f10
fix typos
picnixzDec 1, 2024
8372de6
address Alex's review
picnixzDec 2, 2024
4bcf719
format using a mix of black/ruff/picnixz format
picnixzDec 2, 2024
841a4b1
rename STEALS -> STEAL
picnixzDec 2, 2024
970cbc7
detect more ref. count manageable objects
picnixzDec 2, 2024
4558483
add `lineno` to RETURN values and use kw-only
picnixzDec 2, 2024
b8f6090
use helper for C identifier detection
picnixzDec 2, 2024
db9b6e6
`RefType` -> `RefEffect`
picnixzDec 2, 2024
480f500
improve `ParserReporter`
picnixzDec 2, 2024
9814dd7
disallow stolen ref in return values
picnixzDec 2, 2024
82766b3
add doc
picnixzDec 2, 2024
e7a7a10
fix workflow
picnixzDec 2, 2024
f64a23d
update pre-commit hook
picnixzDec 2, 2024
2eb541f
fix some typos
picnixzDec 2, 2024
cf42e03
restrict the ruff rules
picnixzDec 2, 2024
eb893d0
add ruff docstrings rules
picnixzDec 2, 2024
dbe29a6
address Peter's review
picnixzDec 2, 2024
658e332
update some variable names
picnixzDec 2, 2024
5660ffe
add TODO messages
picnixzDec 2, 2024
afceff0
RefEffect -> Effect
picnixzDec 2, 2024
d173d7a
extract checking logic into smaller functions
picnixzDec 2, 2024
0edd489
add --strict errors mode
picnixzDec 2, 2024
a3becf0
additional stealing effects
picnixzDec 2, 2024
3ac1ff1
Merge remote-tracking branch 'upstream/main' into tools/refcounts/lin…
picnixzDec 2, 2024
baf2474
address Hugo's review
picnixzDec 2, 2024
549ba49
remove TODO symbols for now (we don't want yet to change the Sphinx e…
picnixzDec 2, 2024
c708a4c
address Alex's review
picnixzDec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
address Peter's review
  • Loading branch information
@picnixz
picnixz committedDec 1, 2024
commit58ffbeb5851d27eb0c2168ed6cba103b5226996b
28 changes: 16 additions & 12 deletionsTools/refcounts/lint.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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, NamedTuple
from typing import TYPE_CHECKING, LiteralString

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Mapping
from collections.abc import Callable,Final,Iterable, Mapping

ROOT = Path(__file__).parent.parent.parent.resolve()
DEFAULT_REFCOUNT_DAT_PATH: str = str(ROOT / 'Doc/data/refcounts.dat')
DEFAULT_STABLE_ABI_TOML_PATH: str = str(ROOT / 'Misc/stable_abi.toml')
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 = '...'

Expand DownExpand Up@@ -62,7 +62,8 @@ class RefType(Enum):
STEALS = _auto()
NULL = _auto() # for return values only

class LineInfo(NamedTuple):
@dataclass(slots=True, frozen=True)
class LineInfo:
func: str
ctype: str | None
name: str | None
Expand All@@ -79,12 +80,14 @@ class LineInfo(NamedTuple):
strip_name: bool
strip_reftype: bool

class Return(NamedTuple):
@dataclass(slots=True, frozen=True)
class Return:
ctype: str | None
reftype: RefType | None
comment: str

class Param(NamedTuple):
@dataclass(slots=True, frozen=True)
class Param:
name: str
lineno: int

Expand All@@ -99,7 +102,8 @@ class Signature:
rparam: Return
params: dict[str, Param] = field(default_factory=dict)

class FileView(NamedTuple):
@dataclass(slots=True, frozen=True)
class FileView:
signatures: Mapping[str, Signature]
incomplete: frozenset[str]

Expand DownExpand Up@@ -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()
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)
Expand All@@ -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 = object()
_STABLE_ABI_FILE_SENTINEL: Final = object()

def _create_parser() -> ArgumentParser:
parser = ArgumentParser(
Expand All@@ -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,
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().splitlines()
lines = Path(args.file).read_text(encoding='utf-8').splitlines()
print(' PARSING '.center(80, '-'))
view = parse(lines)
print(' CHECKING '.center(80, '-'))
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp