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

[changelog] Create separate entries for reimported/shadowed-import #7903

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion doc/whatsnew/fragments/4836.bugfix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Update ``reimported`` help message for clarity and add a ``shadowed-import`` message for aliased imports.
Update ``reimported`` help message for clarity.

Closes #4836
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/4836.new_check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add a ``shadowed-import`` message for aliased imports.

Closes #4836
28 changes: 28 additions & 0 deletions script/check_newsfragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import argparse
import difflib
import re
import sys
from pathlib import Path
Expand All @@ -20,6 +21,21 @@
"Follow-up in",
"Fixes part of",
]
VALID_FILE_TYPE = frozenset(
[
"breaking",
"user_action",
"feature",
"new_check",
"removed_check",
"extension",
"false_positive",
"false_negative",
"bugfix",
"other",
"internal",
]
)
ISSUES_KEYWORDS = "|".join(VALID_ISSUES_KEYWORDS)
VALID_CHANGELOG_PATTERN = rf"(?P<description>(.*\n)*(.*\.\n))\n(?P<ref>({ISSUES_KEYWORDS}) (PyCQA/astroid)?#(?P<issue>\d+))"
VALID_CHANGELOG_COMPILED_PATTERN: Pattern[str] = re.compile(
Expand Down Expand Up @@ -55,6 +71,18 @@ def check_file(file: Path, verbose: bool) -> bool:
f"{file} must be named '{issue}.<fragmenttype>', after the issue it references."
)
return False
if not any(file.suffix.endswith(t) for t in VALID_FILE_TYPE):
suggestions = difflib.get_close_matches(file.suffix, VALID_FILE_TYPE)
if suggestions:
multiple_suggestions = "', '".join(f"{issue}.{s}" for s in suggestions)
suggestion = f"should probably be named '{multiple_suggestions}'"
else:
multiple_suggestions = "', '".join(
f"{issue}.{s}" for s in VALID_FILE_TYPE
)
suggestion = f"must be named one of '{multiple_suggestions}'"
echo(f"{file} {suggestion} instead.")
return False
if verbose:
echo(f"Checked '{file}': LGTM πŸ€–πŸ‘")
return True
Expand Down