[flake8-bugbear] Re-raise all exceptions with proper exception chaining
This commit is contained in:
		
							parent
							
								
									7eef4619d5
								
							
						
					
					
						commit
						fcb818b73c
					
				| 
						 | 
				
			
			@ -151,7 +151,6 @@ ignore = [
 | 
			
		|||
    "B018", # Found useless expression.
 | 
			
		||||
    "B023", # Function definition does not bind loop variable `warning`
 | 
			
		||||
    "B028", # No explicit `stacklevel` keyword argument found
 | 
			
		||||
    "B904", # Within an `except` clause, raise exceptions with `raise ... from err`
 | 
			
		||||
    # pycodestyle ignore
 | 
			
		||||
    # pytest can do weird low-level things, and we usually know
 | 
			
		||||
    # what we're doing when we use type(..) is ...
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ def prepare_release_pr(
 | 
			
		|||
        )
 | 
			
		||||
    except InvalidFeatureRelease as e:
 | 
			
		||||
        print(f"{Fore.RED}{e}")
 | 
			
		||||
        raise SystemExit(1)
 | 
			
		||||
        raise SystemExit(1) from None
 | 
			
		||||
 | 
			
		||||
    print(f"Version: {Fore.CYAN}{version}")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -232,17 +232,17 @@ class TerminalWriter:
 | 
			
		|||
                # which may lead to the previous color being propagated to the
 | 
			
		||||
                # start of the expression, so reset first.
 | 
			
		||||
                return "\x1b[0m" + highlighted
 | 
			
		||||
            except pygments.util.ClassNotFound:
 | 
			
		||||
            except pygments.util.ClassNotFound as e:
 | 
			
		||||
                raise UsageError(
 | 
			
		||||
                    "PYTEST_THEME environment variable had an invalid value: '{}'. "
 | 
			
		||||
                    "Only valid pygment styles are allowed.".format(
 | 
			
		||||
                        os.getenv("PYTEST_THEME")
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            except pygments.util.OptionError:
 | 
			
		||||
                ) from e
 | 
			
		||||
            except pygments.util.OptionError as e:
 | 
			
		||||
                raise UsageError(
 | 
			
		||||
                    "PYTEST_THEME_MODE environment variable had an invalid value: '{}'. "
 | 
			
		||||
                    "The only allowed values are 'dark' and 'light'.".format(
 | 
			
		||||
                        os.getenv("PYTEST_THEME_MODE")
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
                ) from e
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1848,13 +1848,13 @@ def parse_warning_filter(
 | 
			
		|||
    try:
 | 
			
		||||
        action: "warnings._ActionKind" = warnings._getaction(action_)  # type: ignore[attr-defined]
 | 
			
		||||
    except warnings._OptionError as e:
 | 
			
		||||
        raise UsageError(error_template.format(error=str(e)))
 | 
			
		||||
        raise UsageError(error_template.format(error=str(e))) from None
 | 
			
		||||
    try:
 | 
			
		||||
        category: Type[Warning] = _resolve_warning_category(category_)
 | 
			
		||||
    except Exception:
 | 
			
		||||
        exc_info = ExceptionInfo.from_current()
 | 
			
		||||
        exception_text = exc_info.getrepr(style="native")
 | 
			
		||||
        raise UsageError(error_template.format(error=exception_text))
 | 
			
		||||
        raise UsageError(error_template.format(error=exception_text)) from None
 | 
			
		||||
    if message and escape:
 | 
			
		||||
        message = re.escape(message)
 | 
			
		||||
    if module and escape:
 | 
			
		||||
| 
						 | 
				
			
			@ -1867,7 +1867,7 @@ def parse_warning_filter(
 | 
			
		|||
        except ValueError as e:
 | 
			
		||||
            raise UsageError(
 | 
			
		||||
                error_template.format(error=f"invalid lineno {lineno_!r}: {e}")
 | 
			
		||||
            )
 | 
			
		||||
            ) from None
 | 
			
		||||
    else:
 | 
			
		||||
        lineno = 0
 | 
			
		||||
    return action, message, category, module, lineno
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue