GeezerVison is showing github.com — Emit a friendlier warning on invalid exclude regex, instead of a stacktrace by wyattscarpenter · Pull Request #19102 · python/mypy
Conversation
If an invalid exclude is used, the error message
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\__main__.py", line 37, in <module>
console_entry()
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\__main__.py", line 15, in console_entry
main()
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\main.py", line 89, in main
sources, options = process_options(args, stdout=stdout, stderr=stderr, fscache=fscache)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\main.py", line 1531, in process_options
targets = create_source_list(special_opts.files, options, fscache)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\find_sources.py", line 48, in create_source_list
sub_sources = finder.find_sources_in_dir(path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\find_sources.py", line 121, in find_sources_in_dir
if matches_exclude(subpath, self.exclude, self.fscache, self.verbosity >= 2):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\files\gits\wyattscarpenter\!!! contributory forks\mypy\mypy\modulefinder.py", line 687, in matches_exclude
if re.search(exclude, subpath_str):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\__init__.py", line 177, in search
return _compile(pattern, flags).search(string)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\__init__.py", line 307, in _compile
p = _compiler.compile(pattern, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\_compiler.py", line 750, in compile
p = _parser.parse(p, flags)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\_parser.py", line 979, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\_parser.py", line 460, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\_parser.py", line 544, in _parse
code = _escape(source, this, state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wyatt\AppData\Local\Programs\Python\Python312\Lib\re\_parser.py", line 443, in _escape
raise source.error("bad escape %s" % escape, len(escape))
re.error: bad escape \p at position 2
now looks like this:
error: The exclude ..\publish is an invalid regular expression, because: bad escape \p at position 2
(Hint: use / as a path separator, even if you're on Windows!)
For more information on Python's flavor of regex, see: https://docs.python.org/3/library/re.html
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
based on Jelle's review, I realized that mypy is pretty consistent about sending usage errors to stderr, and so I have fixed both my code and the code I modelled by code after to do that instead
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|