Skip to content

Commit

Permalink
Fix linting and static typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Aug 12, 2022
1 parent a34f319 commit 19d8a42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions elementpath/tdop.py
Expand Up @@ -421,7 +421,7 @@ class Parser(Generic[TK_co], metaclass=ParserMeta):

_start_token: TK_co
source: str
tokens: Iterator[str]
tokens: Iterator[Match[str]]
token: TK_co
next_token: TK_co
next_match: Optional[Match[str]]
Expand Down Expand Up @@ -456,7 +456,7 @@ def parse(self, source: str) -> TK_co:
assert self.tokenizer, "Parser tokenizer is not built!"
try:
try:
self.tokens = iter(cast(Iterator[str], self.tokenizer.finditer(source)))
self.tokens = iter(self.tokenizer.finditer(source))
except TypeError as err:
token = self.symbol_table['(invalid)'](self, source)
raise token.wrong_syntax('invalid source type, {}'.format(err))
Expand Down Expand Up @@ -486,7 +486,9 @@ def advance(self, *symbols: str) -> TK_co:
raise self.next_token.wrong_syntax()

self.token = self.next_token

for self.next_match in self.tokens:
assert self.next_match is not None
if not self.next_match.group().isspace():
break
else:
Expand Down Expand Up @@ -553,7 +555,7 @@ def advance_until(self, *stop_symbols: str) -> str:
source_chunk: List[str] = []
while True:
try:
self.next_match = cast(Match[str], next(self.tokens))
self.next_match = next(self.tokens)
except StopIteration:
self.next_token = self.symbol_table['(end)'](self)
break
Expand Down
4 changes: 3 additions & 1 deletion elementpath/xpath1/xpath1_parser.py
Expand Up @@ -169,7 +169,9 @@ def proxy(cls, symbol: str, label: str = 'proxy', bp: int = 90) -> Type[ProxyTok
# Move the token class before register the proxy token
token_cls = cls.symbol_table.pop(symbol)
cls.symbol_table[f'{{{token_cls.namespace}}}{symbol}'] = token_cls
return cls.register(symbol, bases=(ProxyToken,), label=label, lbp=bp, rbp=bp)

proxy_class = cls.register(symbol, bases=(ProxyToken,), label=label, lbp=bp, rbp=bp)
return cast(Type[ProxyToken], proxy_class)

@classmethod
def axis(cls, symbol: str, reverse_axis: bool = False, bp: int = 80) -> Type[XPathAxis]:
Expand Down
12 changes: 7 additions & 5 deletions elementpath/xpath_token.py
Expand Up @@ -1146,7 +1146,7 @@ class ProxyToken(XPathToken):
"""
label = 'proxy function'

def nud(self):
def nud(self) -> XPathToken:
namespace = self.namespace or XPATH_FUNCTIONS_NAMESPACE
expanded_name = '{%s}%s' % (namespace, self.value)
try:
Expand Down Expand Up @@ -1645,17 +1645,19 @@ def __call__(self, context: Optional[XPathContext] = None,
except IndexError:
self.error('FOAY0001')

def put(self, position: int, member: Any,
context: Optional[XPathContext] = None) -> 'XPathArray':
def put(self, position: int, member: Any, context: Optional[XPathContext] = None) \
-> 'XPathArray':
if position <= 0:
self.error('FOAY0002' if position else 'FOAY0001')

other = XPathArray(self.parser)
other.extend(self._items)
other.evaluate(context)
assert other._array is not None

try:
other._array[position - 1] = member
except IndexError:
self.error('FOAY0001')
else:
return other

return other

0 comments on commit 19d8a42

Please sign in to comment.