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

Add support for *-wildcards in ignore-undeclared and ignore-unused #479

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jherland
Copy link
Member

@jherland jherland commented Mar 4, 2025

Fixes #478.

Allow *-wildcards in values passed to the ignore_undeclared and ignore_unused settings.

The objective is to allow simple catch-all values, such as pytest-* or types-*.

One or more * is allowed in each ignore-value. Each * will match zero of more characters of any kind. No other wildcard syntax (e.g. using ?, [...] or {...}) is allowed at this point.

Technically, each * in an ignore string is replaced with .* and the resulting string is then interpreted as an RE pattern.
This pattern is then matched against undeclared import names (in the case of ignore_undeclared) or unused package names (in the case of ignore_unused).

Commits:

  • package: Preserve "-stubs" suffix in normalization
  • WIP: ignore_{undeclared,unused}: Accept *-wildcards

@jherland jherland force-pushed the jherland/support-ignore-wildcards branch 4 times, most recently from ec489ca to 0424cc3 Compare March 7, 2025 18:25
@jherland jherland marked this pull request as ready for review March 7, 2025 18:25
@jherland jherland added this to the FawltyDeps 1.0 milestone Mar 7, 2025
@jherland jherland linked an issue Mar 7, 2025 that may be closed by this pull request
Base automatically changed from jherland/drop-python-38-followup to main March 11, 2025 16:30
@jherland jherland force-pushed the jherland/support-ignore-wildcards branch from 0424cc3 to cfd0735 Compare March 11, 2025 16:32
Also document why this suffix is so special.
The '*' wildcards are translated into `.*` regular expression tokens
(which match anything), and then passed to re.fullmatch(), which I believe
should do exactly what we want in this case. That said, we need to take
extra care to avoid injection of regexp special chars in the ignore
patterns, so all other parts of the pattern are filtered through
re.escape().
Add any package starting with "pytest-" to our default ignore_unused
set. This should match pytest plugins that are commonly used together
with pytest (also in our default ignore_unused set).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support wildcards in ignore-unused.
1 participant