python / python/mypy

Per-module options patterns starting with *

Open
#8,522 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-2-low topic-configuration
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Hi,
I am experimenting with per-module options and came across weird behavior when module patterns start with star. Documentation does not explicitly say if this is allowed or not, but I would assume it would work the same way as if it was "in the middle" of pattern. And IMHO there is no reason not to support it.

First issue:

From documentation:

Stars match zero or more module components

This is not the case for stars at the start of the string. For example [mypy-*.foo.bar] does not match module foo.bar

>>> import re
>>> from mypy.options import Options
>>> pattern = Options().compile_glob("*.foo.bar")
re.compile('.*\\.foo\\.bar\\Z')
>>> bool(re.match(pattern, "foo.bar"))
False

Second issue:

[mypy-*] does not match anything. I know that it does not make sense to use this since it is the same as global config, but it would be nice to work nonetheless.

In this case it is a bit more difficult: compile_glob returns correct re.compile('.*\\Z'), but there is some flawed logic in build_per_module_cache(), where it gets to concrete section since it does not end with ".*"


Python: 3.7.2
Mypy: 0.770

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in mypy/options.py with Options.compile_glob() and build_per_module_cache(), then reproduce the two examples from the issue for *.foo.bar and *. Verify how the patterns are classified and ensure leading-star patterns behave consistently with the documented rule that stars match zero or more module components.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.