"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tools/upgrade/errors.py" between
pyre-check-0.0.53.tar.gz and pyre-check-0.0.54.tar.gz

About: Pyre is a performant type checker for Python (ships with Pysa, a security focused static analysis tool).

errors.py  (pyre-check-0.0.53):errors.py  (pyre-check-0.0.54)
skipping to change at line 17 skipping to change at line 17
import json import json
import logging import logging
import re import re
import subprocess import subprocess
import sys import sys
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, cast from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, cast
import libcst import libcst
import libcst.matchers as libcst_matchers
from . import UserError, ast from . import UserError, ast
LOG: logging.Logger = logging.getLogger(__name__) LOG: logging.Logger = logging.getLogger(__name__)
MAX_LINES_PER_FIXME: int = 4 MAX_LINES_PER_FIXME: int = 4
class LineBreakTransformer(libcst.CSTTransformer): class LineBreakTransformer(libcst.CSTTransformer):
def leave_SimpleWhitespace( def leave_SimpleWhitespace(
self, self,
original_node: libcst.SimpleWhitespace, original_node: libcst.SimpleWhitespace,
skipping to change at line 44 skipping to change at line 45
), ),
comment=None, comment=None,
newline=libcst.Newline(), newline=libcst.Newline(),
) )
last_line = libcst.SimpleWhitespace(value=whitespace.split("\n")[1]) last_line = libcst.SimpleWhitespace(value=whitespace.split("\n")[1])
return libcst.ParenthesizedWhitespace( return libcst.ParenthesizedWhitespace(
first_line=first_line, empty_lines=[], indent=True, last_line=la st_line first_line=first_line, empty_lines=[], indent=True, last_line=la st_line
) )
return updated_node return updated_node
@staticmethod
def basic_parenthesize(
node: libcst.CSTNode,
whitespace: Optional[libcst.BaseParenthesizableWhitespace] = None,
) -> libcst.CSTNode:
if not hasattr(node, "lpar"):
return node
if whitespace:
return node.with_changes(
lpar=[libcst.LeftParen(whitespace_after=whitespace)],
rpar=[libcst.RightParen()],
)
return node.with_changes(lpar=[libcst.LeftParen()], rpar=[libcst.RightPa
ren()])
def leave_Assert(
self, original_node: libcst.Assert, updated_node: libcst.Assert
) -> libcst.Assert:
test = updated_node.test
if not test:
return updated_node
assert_whitespace = updated_node.whitespace_after_assert
if isinstance(assert_whitespace, libcst.ParenthesizedWhitespace):
return updated_node.with_changes(
test=LineBreakTransformer.basic_parenthesize(test, assert_whites
pace),
whitespace_after_assert=libcst.SimpleWhitespace(value=" "),
)
return updated_node.with_changes(
test=LineBreakTransformer.basic_parenthesize(test)
)
def leave_Assign( def leave_Assign(
self, original_node: libcst.Assign, updated_node: libcst.Assign self, original_node: libcst.Assign, updated_node: libcst.Assign
) -> libcst.Assign: ) -> libcst.Assign:
assign_value = updated_node.value assign_value = updated_node.value
if hasattr(assign_value, "lpar"): assign_whitespace = updated_node.targets[-1].whitespace_after_equal
parenthesized_value = assign_value.with_changes( if libcst_matchers.matches(
lpar=[libcst.LeftParen()], rpar=[libcst.RightParen()] assign_whitespace, libcst_matchers.ParenthesizedWhitespace()
):
adjusted_target = updated_node.targets[-1].with_changes(
whitespace_after_equal=libcst.SimpleWhitespace(value=" ")
) )
return updated_node.with_changes(value=parenthesized_value) updated_targets = list(updated_node.targets[:-1])
return updated_node updated_targets.append(adjusted_target)
return updated_node.with_changes(
targets=tuple(updated_targets),
value=LineBreakTransformer.basic_parenthesize(
assign_value, assign_whitespace
),
)
return updated_node.with_changes(
value=LineBreakTransformer.basic_parenthesize(assign_value)
)
def leave_Del(
self, original_node: libcst.Del, updated_node: libcst.Del
) -> libcst.Del:
delete_target = updated_node.target
delete_whitespace = updated_node.whitespace_after_del
if isinstance(delete_whitespace, libcst.ParenthesizedWhitespace):
return updated_node.with_changes(
target=LineBreakTransformer.basic_parenthesize(
delete_target, delete_whitespace
),
whitespace_after_del=libcst.SimpleWhitespace(value=" "),
)
return updated_node.with_changes(
target=LineBreakTransformer.basic_parenthesize(delete_target)
)
def leave_Raise(
self, original_node: libcst.Raise, updated_node: libcst.Raise
) -> libcst.Raise:
exception = updated_node.exc
if not exception:
return updated_node
raise_whitespace = updated_node.whitespace_after_raise
if isinstance(raise_whitespace, libcst.ParenthesizedWhitespace):
return updated_node.with_changes(
exc=LineBreakTransformer.basic_parenthesize(
exception, raise_whitespace
),
whitespace_after_raise=libcst.SimpleWhitespace(value=" "),
)
return updated_node.with_changes(
exc=LineBreakTransformer.basic_parenthesize(exception)
)
def leave_Return(
self, original_node: libcst.Return, updated_node: libcst.Return
) -> libcst.Return:
return_value = updated_node.value
if not return_value:
return updated_node
return_whitespace = updated_node.whitespace_after_return
if isinstance(return_whitespace, libcst.ParenthesizedWhitespace):
return updated_node.with_changes(
value=LineBreakTransformer.basic_parenthesize(
return_value, return_whitespace
),
whitespace_after_return=libcst.SimpleWhitespace(value=" "),
)
return updated_node.with_changes(
value=LineBreakTransformer.basic_parenthesize(return_value)
)
class PartialErrorSuppression(Exception): class PartialErrorSuppression(Exception):
def __init__(self, message: str, unsuppressed_paths: List[str]) -> None: def __init__(self, message: str, unsuppressed_paths: List[str]) -> None:
super().__init__(message) super().__init__(message)
self.unsuppressed_paths: List[str] = unsuppressed_paths self.unsuppressed_paths: List[str] = unsuppressed_paths
def error_path(error: Dict[str, Any]) -> str: def error_path(error: Dict[str, Any]) -> str:
return error["path"] return error["path"]
class Errors: class Errors:
 End of changes. 4 change blocks. 
5 lines changed or deleted 102 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)