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

AttributeError: 'str' object has no attribute 'search' #236

Closed
Jacobfaib opened this issue Oct 19, 2023 · 4 comments · Fixed by #237
Closed

AttributeError: 'str' object has no attribute 'search' #236

Jacobfaib opened this issue Oct 19, 2023 · 4 comments · Fixed by #237

Comments

@Jacobfaib
Copy link

Jacobfaib commented Oct 19, 2023

Describe the bug
If you define exclusion_regex in setup.cfg, the string is treated as a regex pattern object leading to:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/vermin/detection.py", line 484, in detect_paths_incremental
    if any(ic in path for ic in ignore_chars) or config.is_excluded_by_regex(path):
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/vermin/config.py", line 338, in is_excluded_by_regex
    return any(regex.search(path) for regex in self.__exclusion_regex)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/vermin/config.py", line 338, in <genexpr>
    return any(regex.search(path) for regex in self.__exclusion_regex)
               ^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'search'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/bin/vermin", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/vermin/main.py", line 39, in main
    paths = list(set(detect_paths(paths, hidden=config.analyze_hidden(),
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/vermin/detection.py", line 531, in detect_paths
    for (acc, further_args) in act(args):
  File "/opt/homebrew/Cellar/[email protected]/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/pool.py", line 873, in next
    raise value
AttributeError: 'str' object has no attribute 'search'

To Reproduce

$ python3 -m pip install -U vermin
$ mkdir repro && cd repro
$ echo -e "[vermin]\nexclusion_regex =\n    'foo/'" > setup.cfg
$ touch foo.py
$ vermin ./foo.py # boom

Expected behavior
No exception

Environment (please complete the following information):

$ vermin --version
1.5.2
$ python3 --version
Python 3.11.6
@netromdk
Copy link
Owner

Thank you for reporting this! I will take a look.

@netromdk
Copy link
Owner

netromdk commented Oct 19, 2023

I have fixed the issue now. Thanks again!

Note that at new release will come soon that will include this fix among other things.

@Jacobfaib
Copy link
Author

Note that at new release will come soon that will include this fix among other things.

Out of curiosity, do you have a rough estimate of when this release will be?

@netromdk
Copy link
Owner

Note that at new release will come soon that will include this fix among other things.

Out of curiosity, do you have a rough estimate of when this release will be?

Maybe within a week or so. I should be almost done with the Python 3.12 support.

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 a pull request may close this issue.

2 participants