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

Correctly match package/module names in import hook #144

Merged
merged 2 commits into from Aug 22, 2020
Merged

Correctly match package/module names in import hook #144

merged 2 commits into from Aug 22, 2020

Commits on Aug 14, 2020

  1. Correctly match package/module names in import hook

    The previously used regular expression tried to handle both exact
    matches and and prefix matches in one go, using this approach:
    
        re.compile(r'^%s\.?' % pkg)
    
    However, this is incorrect, since the literal dot is optional in the
    pattern, causing longer matches to also get included. For example, ‘foo’
    should match ‘foo’ and ‘foo.bar’, but it also incorrectly matches
    ‘foobar’:
    
        >>> re.compile(r'^foo\.?').match('foobar')
        <_sre.SRE_Match object; span=(0, 3), match='foo'>
    
    In practice, a command like this (using the pytest plugin as an example)
    is supposed to check the ‘flask’ package and any modules below it:
    
        pytest --typeguard-packages=flask
    
    ... but in reality it also checks other packages, such as
    ‘flask_sqlalchemy’ and ‘flask_redis’, if those happen to be installed.
    
    This can be easily fixed by not using regular expression, but simple
    string matching instead.
    wbolster committed Aug 14, 2020
    Copy the full SHA
    b31e1a1 View commit details
    Browse the repository at this point in the history

Commits on Aug 21, 2020

  1. Copy the full SHA
    d2230ca View commit details
    Browse the repository at this point in the history