Skip to content

Commit

Permalink
fix: mypy 1.11 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Jul 20, 2024
1 parent f826115 commit cd41d3e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 175 deletions.
115 changes: 40 additions & 75 deletions peg_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from typing import Any

from peg_parser.subheader import Del, Load, Parser, Store, Target, logger, memoize, memoize_left_rec
from peg_parser.subheader import Del, Load, Node, Parser, Store, Target, logger, memoize, memoize_left_rec


# Keywords and soft keywords are listed at the end of the parser definition.
Expand Down Expand Up @@ -339,7 +339,7 @@ def del_stmt(self) -> ast.Delete | None:
self._reset(mark)
return None

def yield_stmt(self) -> ast.Expr | None:
def yield_stmt(self) -> ast.expr | None:
# yield_stmt: yield_expr
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand Down Expand Up @@ -567,25 +567,14 @@ def class_def_raw(self) -> ast.ClassDef | None:
and (self.expect_forced(self.expect(":"), "':'"))
and (c := self.block())
):
return (
ast.ClassDef(
a.string,
bases=b[0] if b else [],
keywords=b[1] if b else [],
body=c,
decorator_list=[],
type_params=t or [],
**self.span(_lnum, _col),
)
if sys.version_info >= (3, 12)
else ast.ClassDef(
a.string,
bases=b[0] if b else [],
keywords=b[1] if b else [],
body=c,
decorator_list=[],
**self.span(_lnum, _col),
)
return ast.ClassDef(
a.string,
bases=b[0] if b else [],
keywords=b[1] if b else [],
body=c,
decorator_list=[],
**{"type_params": t} if t else {},
**self.span(_lnum, _col),
)
self._reset(mark)
return None
Expand Down Expand Up @@ -620,25 +609,14 @@ def function_def_raw(self) -> ast.FunctionDef | ast.AsyncFunctionDef | None:
and (tc := self.func_type_comment(),)
and (b := self.block())
):
return (
ast.FunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
type_params=t or [],
**self.span(_lnum, _col),
)
if sys.version_info >= (3, 12)
else ast.FunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
**self.span(_lnum, _col),
)
return ast.FunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
**{"type_params": t} if t else {},
**self.span(_lnum, _col),
)
self._reset(mark)
if (
Expand All @@ -654,25 +632,14 @@ def function_def_raw(self) -> ast.FunctionDef | ast.AsyncFunctionDef | None:
and (tc := self.func_type_comment(),)
and (b := self.block())
):
return (
ast.AsyncFunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
type_params=t or [],
**self.span(_lnum, _col),
)
if sys.version_info >= (3, 12)
else ast.AsyncFunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
**self.span(_lnum, _col),
)
return ast.AsyncFunctionDef(
name=n.string,
args=params or self.make_arguments(None, [], None, [], None),
returns=a,
body=b,
type_comment=tc,
**{"type_params": t} if t else {},
**self.span(_lnum, _col),
)
self._reset(mark)
return None
Expand Down Expand Up @@ -885,11 +852,11 @@ def param_star_annotation(self) -> ast.arg | None:
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
if (a := self.name()) and (b := self.star_annotation()):
return ast.arg(arg=a.string, annotations=b, **self.span(_lnum, _col))
return ast.arg(arg=a.string, annotation=b, **self.span(_lnum, _col))
self._reset(mark)
return None

def annotation(self) -> ast.Expr | None:
def annotation(self) -> ast.expr | None:
# annotation: ':' expression
mark = self._mark()
if (self.expect(":")) and (a := self.expression()):
Expand All @@ -905,7 +872,7 @@ def star_annotation(self) -> Any | None:
self._reset(mark)
return None

def default(self) -> ast.Expr | None:
def default(self) -> ast.expr | None:
# default: '=' expression | invalid_default
mark = self._mark()
if (self.expect("=")) and (a := self.expression()):
Expand Down Expand Up @@ -1515,7 +1482,7 @@ def wildcard_pattern(self) -> ast.MatchAs | None:
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
if self.expect("_"):
return ast.MatchAs(pattern=None, target=None, **self.span(_lnum, _col))
return ast.MatchAs(pattern=None, **self.span(_lnum, _col))
self._reset(mark)
return None

Expand Down Expand Up @@ -1606,7 +1573,7 @@ def star_pattern(self) -> Any | None:
return ast.MatchStar(name=target, **self.span(_lnum, _col))
self._reset(mark)
if (self.expect("*")) and (self.wildcard_pattern()):
return ast.MatchStar(target=None, **self.span(_lnum, _col))
return ast.MatchStar(**self.span(_lnum, _col))
self._reset(mark)
return None

Expand Down Expand Up @@ -1786,9 +1753,7 @@ def type_alias(self) -> ast.TypeAlias | None:
type_params=t or [],
value=b,
**self.span(_lnum, _col),
)
if sys.version_info >= (3, 12)
else None,
),
)
self._reset(mark)
return None
Expand Down Expand Up @@ -1877,7 +1842,7 @@ def expressions(self) -> Any | None:
return None

@memoize
def expression(self) -> ast.Expr | Any | None:
def expression(self) -> ast.expr | None:
# expression: invalid_expression | invalid_legacy_expression | disjunction 'if' disjunction 'else' expression | disjunction | lambdef
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand Down Expand Up @@ -2002,7 +1967,7 @@ def named_expression(self) -> Any | None:
return None

@memoize
def disjunction(self) -> Any | None:
def disjunction(self) -> Node | None:
# disjunction: conjunction ((('or' | '||') conjunction))+ | conjunction
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand All @@ -2015,7 +1980,7 @@ def disjunction(self) -> Any | None:
return None

@memoize
def conjunction(self) -> Any | None:
def conjunction(self) -> Node | None:
# conjunction: inversion ((('and' | '&&') inversion))+ | inversion
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand All @@ -2028,7 +1993,7 @@ def conjunction(self) -> Any | None:
return None

@memoize
def inversion(self) -> Any | None:
def inversion(self) -> Node | None:
# inversion: 'not' inversion | comparison
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand All @@ -2040,7 +2005,7 @@ def inversion(self) -> Any | None:
self._reset(mark)
return None

def comparison(self) -> Any | None:
def comparison(self) -> Node | None:
# comparison: bitwise_or compare_op_bitwise_or_pair+ | bitwise_or
mark = self._mark()
_lnum, _col = self._tokenizer.peek().start
Expand Down Expand Up @@ -2908,7 +2873,7 @@ def double_starred_kvpair(self) -> Any | None:
self._reset(mark)
return None

def kvpair(self) -> tuple[ast.Expr, ast.Expr] | None:
def kvpair(self) -> tuple[ast.expr, ast.expr] | None:
# kvpair: expression ':' expression
mark = self._mark()
if (a := self.expression()) and (self.expect(":")) and (b := self.expression()):
Expand Down Expand Up @@ -3478,7 +3443,7 @@ def invalid_kwarg(self) -> None:
self._reset(mark)
return None

def expression_without_invalid(self) -> ast.AST | Any | None:
def expression_without_invalid(self) -> Node | Any | None:
# expression_without_invalid: disjunction 'if' disjunction 'else' expression | disjunction | lambdef
_prev_call_invalid = self.call_invalid_rules
self.call_invalid_rules = False
Expand Down Expand Up @@ -3636,7 +3601,7 @@ def invalid_assignment(self) -> None:
self._reset(mark)
return None

def invalid_ann_assign_target(self) -> ast.AST | None:
def invalid_ann_assign_target(self) -> Node | None:
# invalid_ann_assign_target: plist | ptuple | '(' invalid_ann_assign_target ')'
mark = self._mark()
if a := self.plist():
Expand Down
Loading

0 comments on commit cd41d3e

Please sign in to comment.