Skip to content

Commit

Permalink
revert lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yangdanny97 committed Nov 18, 2024
1 parent 7c84949 commit b3e7ca8
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 79 deletions.
18 changes: 9 additions & 9 deletions src/fixit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def fixit_bytes(
*,
config: Config,
autofix: bool = False,
metrics_hook: MetricsHook | None = None,
metrics_hook: Optional[MetricsHook] = None,
) -> Generator[Result, bool, Optional[FileContent]]:
"""
Lint raw bytes content representing a single path, using the given configuration.
Expand Down Expand Up @@ -154,8 +154,8 @@ def fixit_stdin(
path: Path,
*,
autofix: bool = False,
options: Options | None = None,
metrics_hook: MetricsHook | None = None,
options: Optional[Options] = None,
metrics_hook: Optional[MetricsHook] = None,
) -> Generator[Result, bool, None]:
"""
Wrapper around :func:`fixit_bytes` for formatting content from STDIN.
Expand Down Expand Up @@ -187,8 +187,8 @@ def fixit_file(
path: Path,
*,
autofix: bool = False,
options: Options | None = None,
metrics_hook: MetricsHook | None = None,
options: Optional[Options] = None,
metrics_hook: Optional[MetricsHook] = None,
) -> Generator[Result, bool, None]:
"""
Lint a single file on disk, detecting and generating appropriate configuration.
Expand Down Expand Up @@ -223,8 +223,8 @@ def _fixit_file_wrapper(
path: Path,
*,
autofix: bool = False,
options: Options | None = None,
metrics_hook: MetricsHook | None = None,
options: Optional[Options] = None,
metrics_hook: Optional[MetricsHook] = None,
) -> List[Result]:
"""
Wrapper because generators can't be pickled or used directly via multiprocessing
Expand All @@ -239,9 +239,9 @@ def fixit_paths(
paths: Iterable[Path],
*,
autofix: bool = False,
options: Options | None = None,
options: Optional[Options] = None,
parallel: bool = True,
metrics_hook: MetricsHook | None = None,
metrics_hook: Optional[MetricsHook] = None,
) -> Generator[Result, bool, None]:
"""
Lint multiple files or directories, recursively expanding each path.
Expand Down
10 changes: 5 additions & 5 deletions src/fixit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def f(v: int) -> str:
@click.option("--print-metrics", is_flag=True, help="Print metrics of this run")
def main(
ctx: click.Context,
debug: bool | None,
config_file: Path | None,
debug: Optional[bool],
config_file: Optional[Path],
tags: str,
rules: str,
output_format: OutputFormat | None,
output_format: Optional[OutputFormat],
output_template: str,
print_metrics: bool,
) -> None:
Expand Down Expand Up @@ -258,8 +258,8 @@ def fix(
def lsp(
ctx: click.Context,
stdio: bool,
tcp: int | None,
ws: int | None,
tcp: Optional[int],
ws: Optional[int],
debounce_interval: float,
) -> None:
"""
Expand Down
30 changes: 16 additions & 14 deletions src/fixit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@


class ConfigError(ValueError):
def __init__(self, msg: str, config: RawConfig | None = None):
def __init__(self, msg: str, config: Optional[RawConfig] = None):
super().__init__(msg)
self.config = config

Expand Down Expand Up @@ -203,7 +203,7 @@ def collect_rules(
config: Config,
*,
# out-param to capture reasons when disabling rules for debugging
debug_reasons: Dict[Type[LintRule], str] | None = None,
debug_reasons: Optional[Dict[Type[LintRule], str]] = None,
) -> Collection[LintRule]:
"""
Import and return rules specified by `enables` and `disables`.
Expand Down Expand Up @@ -272,7 +272,7 @@ def collect_rules(
return materialized_rules


def locate_configs(path: Path, root: Path | None = None) -> List[Path]:
def locate_configs(path: Path, root: Optional[Path] = None) -> List[Path]:
"""
Given a file path, locate all relevant config files in priority order.
Expand Down Expand Up @@ -335,7 +335,7 @@ def read_configs(paths: List[Path]) -> List[RawConfig]:


def get_sequence(
config: RawConfig, key: str, *, data: Dict[str, Any] | None = None
config: RawConfig, key: str, *, data: Optional[Dict[str, Any]] = None
) -> Sequence[str]:
value: Sequence[str]
if data:
Expand All @@ -352,7 +352,7 @@ def get_sequence(


def get_options(
config: RawConfig, key: str, *, data: Dict[str, Any] | None = None
config: RawConfig, key: str, *, data: Optional[Dict[str, Any]] = None
) -> RuleOptionsTable:
if data:
mapping = data.pop(key, {})
Expand All @@ -379,7 +379,9 @@ def get_options(
return rule_configs


def parse_rule(rule: str, root: Path, config: RawConfig | None = None) -> QualifiedRule:
def parse_rule(
rule: str, root: Path, config: Optional[RawConfig] = None
) -> QualifiedRule:
"""
Given a raw rule string, parse and return a QualifiedRule object
"""
Expand All @@ -398,7 +400,7 @@ def parse_rule(rule: str, root: Path, config: RawConfig | None = None) -> Qualif


def merge_configs(
path: Path, raw_configs: List[RawConfig], root: Path | None = None
path: Path, raw_configs: List[RawConfig], root: Optional[Path] = None
) -> Config:
"""
Given multiple raw configs, merge them in priority order.
Expand All @@ -411,8 +413,8 @@ def merge_configs(
enable_rules: Set[QualifiedRule] = {QualifiedRule("fixit.rules")}
disable_rules: Set[QualifiedRule] = set()
rule_options: RuleOptionsTable = {}
target_python_version: Version | None = Version(platform.python_version())
target_formatter: str | None = None
target_python_version: Optional[Version] = Version(platform.python_version())
target_formatter: Optional[str] = None
output_format: OutputFormat = OutputFormat.fixit
output_template: str = ""

Expand All @@ -421,9 +423,9 @@ def process_subpath(
*,
enable: Sequence[str] = (),
disable: Sequence[str] = (),
options: RuleOptionsTable | None = None,
options: Optional[RuleOptionsTable] = None,
python_version: Any = None,
formatter: str | None = None,
formatter: Optional[str] = None,
) -> None:
nonlocal target_python_version
nonlocal target_formatter
Expand Down Expand Up @@ -554,10 +556,10 @@ def process_subpath(


def generate_config(
path: Path | None = None,
root: Path | None = None,
path: Optional[Path] = None,
root: Optional[Path] = None,
*,
options: Options | None = None,
options: Optional[Options] = None,
) -> Config:
"""
Given a file path, walk upwards looking for and applying cascading configs
Expand Down
2 changes: 1 addition & 1 deletion src/fixit/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def collect_violations(
self,
rules: Collection[LintRule],
config: Config,
metrics_hook: MetricsHook | None = None,
metrics_hook: Optional[MetricsHook] = None,
) -> Generator[LintViolation, None, int]:
"""Run multiple `LintRule`s and yield any lint violations.
Expand Down
40 changes: 20 additions & 20 deletions src/fixit/ftypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class OutputFormat(str, Enum):
@dataclass(frozen=True)
class Invalid:
code: str
range: CodeRange | None = None
expected_message: str | None = None
expected_replacement: str | None = None
range: Optional[CodeRange] = None
expected_message: Optional[str] = None
expected_replacement: Optional[str] = None


@dataclass(frozen=True)
Expand Down Expand Up @@ -105,8 +105,8 @@ class Valid:

class QualifiedRuleRegexResult(TypedDict):
module: str
name: str | None
local: str | None
name: Optional[str]
local: Optional[str]


def is_sequence(value: Any) -> bool:
Expand All @@ -120,9 +120,9 @@ def is_collection(value: Any) -> bool:
@dataclass(frozen=True)
class QualifiedRule:
module: str
name: str | None = None
local: str | None = None
root: Path | None = field(default=None, hash=False, compare=False)
name: Optional[str] = None
local: Optional[str] = None
root: Optional[Path] = field(default=None, hash=False, compare=False)

def __str__(self) -> str:
return self.module + (f":{self.name}" if self.name else "")
Expand All @@ -139,7 +139,7 @@ class Tags(Container[str]):
exclude: Tuple[str, ...] = ()

@staticmethod
def parse(value: str | None) -> "Tags":
def parse(value: Optional[str]) -> "Tags":
if not value:
return Tags()

Expand Down Expand Up @@ -185,11 +185,11 @@ class Options:
Command-line options to affect runtime behavior
"""

debug: bool | None = None
config_file: Path | None = None
tags: Tags | None = None
debug: Optional[bool] = None
config_file: Optional[Path] = None
tags: Optional[Tags] = None
rules: Sequence[QualifiedRule] = ()
output_format: OutputFormat | None = None
output_format: Optional[OutputFormat] = None
output_template: str = ""
print_metrics: bool = False

Expand All @@ -200,8 +200,8 @@ class LSPOptions:
Command-line options to affect LSP runtime behavior
"""

tcp: int | None
ws: int | None
tcp: Optional[int]
ws: Optional[int]
stdio: bool = True
debounce_interval: float = 0.5

Expand All @@ -226,13 +226,13 @@ class Config:
options: RuleOptionsTable = field(default_factory=dict)

# filtering criteria
python_version: Version | None = field(
python_version: Optional[Version] = field(
default_factory=lambda: Version(platform.python_version())
)
tags: Tags = field(default_factory=Tags)

# post-run processing
formatter: str | None = None
formatter: Optional[str] = None

# output formatting options
output_format: OutputFormat = OutputFormat.fixit
Expand Down Expand Up @@ -263,7 +263,7 @@ class LintViolation:
range: CodeRange
message: str
node: CSTNode
replacement: NodeReplacement[CSTNode] | None
replacement: Optional[NodeReplacement[CSTNode]]
diff: str = ""

@property
Expand All @@ -281,5 +281,5 @@ class Result:
"""

path: Path
violation: LintViolation | None
error: Tuple[Exception, str] | None = None
violation: Optional[LintViolation]
error: Optional[Tuple[Exception, str]] = None
6 changes: 3 additions & 3 deletions src/fixit/lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def load_config(self, path: Path) -> Config:

def diagnostic_generator(
self, uri: str, autofix: bool = False
) -> Generator[Result, bool, Optional[FileContent]] | None:
) -> Optional[Generator[Result, bool, Optional[FileContent]]]:
"""
LSP wrapper (provides document state from `pygls`) for `fixit_bytes`.
"""
Expand Down Expand Up @@ -125,7 +125,7 @@ def on_did_open(self, params: DidOpenTextDocumentParams) -> None:
def on_did_change(self, params: DidChangeTextDocumentParams) -> None:
self.validate(params.text_document.uri, params.text_document.version)

def format(self, params: DocumentFormattingParams) -> List[TextEdit] | None:
def format(self, params: DocumentFormattingParams) -> Optional[List[TextEdit]]:
generator = self.diagnostic_generator(params.text_document.uri, autofix=True)
if generator is None:
return None
Expand Down Expand Up @@ -164,7 +164,7 @@ class Debouncer:
def __init__(self, f: Callable[..., Any], interval: float) -> None:
self.f = f
self.interval = interval
self._timer: threading.Timer | None = None
self._timer: Optional[threading.Timer] = None
self._lock = threading.Lock()

def __call__(self, *args: Any, **kwargs: Any) -> None:
Expand Down
24 changes: 13 additions & 11 deletions src/fixit/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init_subclass__(cls) -> None:
def __str__(self) -> str:
return f"{self.__class__.__module__}:{self.__class__.__name__}"

_visit_hook: VisitHook | None = None
_visit_hook: Optional[VisitHook] = None

def node_comments(self, node: CSTNode) -> Generator[str, None, None]:
"""
Expand All @@ -125,9 +125,11 @@ def node_comments(self, node: CSTNode) -> Generator[str, None, None]:
while not isinstance(node, Module):
# trailing_whitespace can either be a property of the node itself, or in
# case of blocks, be part of the block's body element
tw: TrailingWhitespace | None = getattr(node, "trailing_whitespace", None)
tw: Optional[TrailingWhitespace] = getattr(
node, "trailing_whitespace", None
)
if tw is None:
body: BaseSuite | None = getattr(node, "body", None)
body: Optional[BaseSuite] = getattr(node, "body", None)
if isinstance(body, SimpleStatementSuite):
tw = body.trailing_whitespace
elif isinstance(body, IndentedBlock):
Expand All @@ -136,20 +138,20 @@ def node_comments(self, node: CSTNode) -> Generator[str, None, None]:
if tw and tw.comment:
yield tw.comment.value

comma: Comma | None = getattr(node, "comma", None)
comma: Optional[Comma] = getattr(node, "comma", None)
if isinstance(comma, Comma):
tw = getattr(comma.whitespace_after, "first_line", None)
if tw and tw.comment:
yield tw.comment.value

rb: RightSquareBracket | None = getattr(node, "rbracket", None)
rb: Optional[RightSquareBracket] = getattr(node, "rbracket", None)
if rb is not None:
tw = getattr(rb.whitespace_before, "first_line", None)
if tw and tw.comment:
yield tw.comment.value

el: Sequence[EmptyLine] | None = None
lb: LeftSquareBracket | None = getattr(node, "lbracket", None)
el: Optional[Sequence[EmptyLine]] = None
lb: Optional[LeftSquareBracket] = getattr(node, "lbracket", None)
if lb is not None:
el = getattr(lb.whitespace_after, "empty_lines", None)
if el is not None:
Expand All @@ -163,7 +165,7 @@ def node_comments(self, node: CSTNode) -> Generator[str, None, None]:
if line.comment:
yield line.comment.value

ll: Sequence[EmptyLine] | None = getattr(node, "leading_lines", None)
ll: Optional[Sequence[EmptyLine]] = getattr(node, "leading_lines", None)
if ll is not None:
for line in ll:
if line.comment:
Expand Down Expand Up @@ -217,10 +219,10 @@ def ignore_lint(self, node: CSTNode) -> bool:
def report(
self,
node: CSTNode,
message: str | None = None,
message: Optional[str] = None,
*,
position: Union[CodePosition, CodeRange] | None = None,
replacement: NodeReplacement[CSTNode] | None = None,
position: Optional[Union[CodePosition, CodeRange]] = None,
replacement: Optional[NodeReplacement[CSTNode]] = None,
) -> None:
"""
Report a lint rule violation.
Expand Down
Loading

0 comments on commit b3e7ca8

Please sign in to comment.