]>
git.madduck.net Git - etc/vim.git/blobdiff - black.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
)
from appdirs import user_cache_dir
)
from appdirs import user_cache_dir
-from attr import dataclass, evolve, Factory
+from dataclasses import dataclass, field, replace
import click
import toml
from typed_ast import ast3, ast27
import click
import toml
from typed_ast import ast3, ast27
@dataclass
class FileMode:
@dataclass
class FileMode:
- target_versions: Set[TargetVersion] = Factory( set)
+ target_versions: Set[TargetVersion] = field(default_factory= set)
line_length: int = DEFAULT_LINE_LENGTH
string_normalization: bool = True
is_pyi: bool = False
line_length: int = DEFAULT_LINE_LENGTH
string_normalization: bool = True
is_pyi: bool = False
`mode` and `fast` options are passed to :func:`format_file_contents`.
"""
if src.suffix == ".pyi":
`mode` and `fast` options are passed to :func:`format_file_contents`.
"""
if src.suffix == ".pyi":
- mode = evolv e(mode, is_pyi=True)
+ mode = replac e(mode, is_pyi=True)
then = datetime.utcfromtimestamp(src.stat().st_mtime)
with open(src, "rb") as buf:
then = datetime.utcfromtimestamp(src.stat().st_mtime)
with open(src, "rb") as buf:
"""Keeps track of brackets on a line."""
depth: int = 0
"""Keeps track of brackets on a line."""
depth: int = 0
- bracket_match: Dict[Tuple[Depth, NodeType], Leaf] = Factory( dict)
- delimiters: Dict[LeafID, Priority] = Factory( dict)
+ bracket_match: Dict[Tuple[Depth, NodeType], Leaf] = field(default_factory= dict)
+ delimiters: Dict[LeafID, Priority] = field(default_factory= dict)
previous: Optional[Leaf] = None
previous: Optional[Leaf] = None
- _for_loop_depths: List[int] = Factory( list)
- _lambda_argument_depths: List[int] = Factory( list)
+ _for_loop_depths: List[int] = field(default_factory= list)
+ _lambda_argument_depths: List[int] = field(default_factory= list)
def mark(self, leaf: Leaf) -> None:
"""Mark `leaf` with bracket-related metadata. Keep track of delimiters.
def mark(self, leaf: Leaf) -> None:
"""Mark `leaf` with bracket-related metadata. Keep track of delimiters.
"""Holds leaves and comments. Can be printed with `str(line)`."""
depth: int = 0
"""Holds leaves and comments. Can be printed with `str(line)`."""
depth: int = 0
- leaves: List[Leaf] = Factory(list)
- comments: Dict[LeafID, List[Leaf]] = Factory(dict) # keys ordered like `leaves`
- bracket_tracker: BracketTracker = Factory(BracketTracker)
+ leaves: List[Leaf] = field(default_factory=list)
+ # keys ordered like `leaves`
+ comments: Dict[LeafID, List[Leaf]] = field(default_factory=dict)
+ bracket_tracker: BracketTracker = field(default_factory=BracketTracker)
inside_brackets: bool = False
should_explode: bool = False
inside_brackets: bool = False
should_explode: bool = False
is_pyi: bool = False
previous_line: Optional[Line] = None
previous_after: int = 0
is_pyi: bool = False
previous_line: Optional[Line] = None
previous_after: int = 0
- previous_defs: List[int] = Factory( list)
+ previous_defs: List[int] = field(default_factory= list)
def maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
"""Return the number of extra empty lines before and after the `current_line`.
def maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]:
"""Return the number of extra empty lines before and after the `current_line`.
is_pyi: bool = False
normalize_strings: bool = True
is_pyi: bool = False
normalize_strings: bool = True
- current_line: Line = Factory( Line)
+ current_line: Line = field(default_factory= Line)
remove_u_prefix: bool = False
def line(self, indent: int = 0) -> Iterator[Line]:
remove_u_prefix: bool = False
def line(self, indent: int = 0) -> Iterator[Line]:
node.insert_child(index, Node(syms.atom, [lpar, operand, rpar]))
yield from self.visit_default(node)
node.insert_child(index, Node(syms.atom, [lpar, operand, rpar]))
yield from self.visit_default(node)
- def __attrs_ post_init__(self) -> None:
+ def __post_init__(self) -> None:
"""You are in a twisty little maze of passages."""
v = self.visit_stmt
Ø: Set[str] = set()
"""You are in a twisty little maze of passages."""
v = self.visit_stmt
Ø: Set[str] = set()
"""
container: Optional[LN] = container_of(leaf)
while container is not None and container.type != token.ENDMARKER:
"""
container: Optional[LN] = container_of(leaf)
while container is not None and container.type != token.ENDMARKER:
for comment in list_comments(container.prefix, is_endmarker=False):
if comment.value in FMT_ON:
for comment in list_comments(container.prefix, is_endmarker=False):
if comment.value in FMT_ON:
+ is_fmt_on = True
+ elif comment.value in FMT_OFF:
+ is_fmt_on = False
+ if is_fmt_on:
+ return
yield f"{' ' * depth}{node.__class__.__name__}("
yield f"{' ' * depth}{node.__class__.__name__}("
- for field in sorted(node._fields):
+ for field in sorted(node._fields): # noqa: F402
# TypeIgnore has only one field 'lineno' which breaks this comparison
type_ignore_classes = (ast3.TypeIgnore, ast27.TypeIgnore)
if sys.version_info >= (3, 8):
# TypeIgnore has only one field 'lineno' which breaks this comparison
type_ignore_classes = (ast3.TypeIgnore, ast27.TypeIgnore)
if sys.version_info >= (3, 8):