mypy: add temporary variables to ease type checking
This commit is contained in:
parent
b05b1b16c1
commit
ce4124d5dd
@ -274,7 +274,7 @@ class Lexer:
|
|||||||
self.filenames: typing.List[str] = []
|
self.filenames: typing.List[str] = []
|
||||||
self._filenames_set: typing.Set[str] = set()
|
self._filenames_set: typing.Set[str] = set()
|
||||||
|
|
||||||
if self.filename:
|
if filename:
|
||||||
self.filenames.append(filename)
|
self.filenames.append(filename)
|
||||||
self._filenames_set.add(filename)
|
self._filenames_set.add(filename)
|
||||||
|
|
||||||
@ -334,10 +334,10 @@ class Lexer:
|
|||||||
|
|
||||||
del self.comments[:]
|
del self.comments[:]
|
||||||
|
|
||||||
comments = "\n".join(comments)
|
comment_str = "\n".join(comments)
|
||||||
del self.comments[:]
|
del self.comments[:]
|
||||||
if comments:
|
if comment_str:
|
||||||
return comments
|
return comment_str
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -220,6 +220,8 @@ class CxxParser:
|
|||||||
match_stack = deque((token_map[tok.type] for tok in consumed))
|
match_stack = deque((token_map[tok.type] for tok in consumed))
|
||||||
get_token = self.lex.token
|
get_token = self.lex.token
|
||||||
|
|
||||||
|
tok: typing.Optional[LexToken]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
tok = get_token()
|
tok = get_token()
|
||||||
consumed.append(tok)
|
consumed.append(tok)
|
||||||
@ -710,10 +712,12 @@ class CxxParser:
|
|||||||
break
|
break
|
||||||
|
|
||||||
# multiple attributes can be specified
|
# multiple attributes can be specified
|
||||||
tok = self.lex.token_if(*self._attribute_specifier_seq_start_types)
|
maybe_tok = self.lex.token_if(*self._attribute_specifier_seq_start_types)
|
||||||
if tok is None:
|
if maybe_tok is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
tok = maybe_tok
|
||||||
|
|
||||||
# TODO return attrs
|
# TODO return attrs
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1202,10 +1206,13 @@ class CxxParser:
|
|||||||
props.update(dict.fromkeys(mods.vars.keys(), True))
|
props.update(dict.fromkeys(mods.vars.keys(), True))
|
||||||
|
|
||||||
if is_class_block:
|
if is_class_block:
|
||||||
|
access = self._current_access
|
||||||
|
assert access is not None
|
||||||
|
|
||||||
f = Field(
|
f = Field(
|
||||||
name=name,
|
name=name,
|
||||||
type=dtype,
|
type=dtype,
|
||||||
access=self._current_access,
|
access=access,
|
||||||
value=default,
|
value=default,
|
||||||
bits=bits,
|
bits=bits,
|
||||||
doxygen=doxygen,
|
doxygen=doxygen,
|
||||||
@ -1713,6 +1720,9 @@ class CxxParser:
|
|||||||
|
|
||||||
method: Method
|
method: Method
|
||||||
|
|
||||||
|
current_access = self._current_access
|
||||||
|
assert current_access is not None
|
||||||
|
|
||||||
if op:
|
if op:
|
||||||
method = Operator(
|
method = Operator(
|
||||||
return_type,
|
return_type,
|
||||||
@ -1722,8 +1732,8 @@ class CxxParser:
|
|||||||
doxygen=doxygen,
|
doxygen=doxygen,
|
||||||
operator=op,
|
operator=op,
|
||||||
template=template,
|
template=template,
|
||||||
access=self._current_access,
|
access=current_access,
|
||||||
**props,
|
**props, # type: ignore
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
method = Method(
|
method = Method(
|
||||||
@ -1735,8 +1745,8 @@ class CxxParser:
|
|||||||
constructor=constructor,
|
constructor=constructor,
|
||||||
destructor=destructor,
|
destructor=destructor,
|
||||||
template=template,
|
template=template,
|
||||||
access=self._current_access,
|
access=current_access,
|
||||||
**props,
|
**props, # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
self._parse_method_end(method)
|
self._parse_method_end(method)
|
||||||
@ -1772,6 +1782,10 @@ class CxxParser:
|
|||||||
raise CxxParseError(
|
raise CxxParseError(
|
||||||
"typedef name may not be a nested-name-specifier"
|
"typedef name may not be a nested-name-specifier"
|
||||||
)
|
)
|
||||||
|
name: typing.Optional[str] = getattr(pqname.segments[0], "name", None)
|
||||||
|
if not name:
|
||||||
|
raise CxxParseError("typedef function must have a name")
|
||||||
|
|
||||||
if fn.constexpr:
|
if fn.constexpr:
|
||||||
raise CxxParseError("typedef function may not be constexpr")
|
raise CxxParseError("typedef function may not be constexpr")
|
||||||
if fn.extern:
|
if fn.extern:
|
||||||
@ -1798,7 +1812,7 @@ class CxxParser:
|
|||||||
msvc_convention=fn.msvc_convention,
|
msvc_convention=fn.msvc_convention,
|
||||||
)
|
)
|
||||||
|
|
||||||
typedef = Typedef(fntype, pqname.segments[0].name, self._current_access)
|
typedef = Typedef(fntype, name, self._current_access)
|
||||||
self.visitor.on_typedef(state, typedef)
|
self.visitor.on_typedef(state, typedef)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@ -1861,9 +1875,10 @@ class CxxParser:
|
|||||||
self._parse_trailing_return_type(dtype)
|
self._parse_trailing_return_type(dtype)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
msvc_convention = self.lex.token_if_val(*self._msvc_conventions)
|
msvc_convention = None
|
||||||
if msvc_convention:
|
msvc_convention_tok = self.lex.token_if_val(*self._msvc_conventions)
|
||||||
msvc_convention = msvc_convention.value
|
if msvc_convention_tok:
|
||||||
|
msvc_convention = msvc_convention_tok.value
|
||||||
|
|
||||||
# Check to see if this is a grouping paren or something else
|
# Check to see if this is a grouping paren or something else
|
||||||
if not self.lex.token_peek_if("*", "&"):
|
if not self.lex.token_peek_if("*", "&"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user