summaryrefslogtreecommitdiff
path: root/SCons/cpp.py
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2023-05-01 11:54:48 -0600
committerMats Wichmann <mats@linux.com>2023-05-01 12:06:45 -0600
commit1a103470a13a83590b3fc06e8779494e2b99751d (patch)
treeab4b5fcdbc2504ff1436387dbe82db2dcedff22b /SCons/cpp.py
parent0ef81fc03600cd275a8e6733aeca26e0db268dad (diff)
downloadscons-git-1a103470a13a83590b3fc06e8779494e2b99751d.tar.gz
Add some cheap return and parameter annotations
Use: https://github.com/JelleZijlstra/autotyping to add "safe" return annotations. Where a parameter has a default value that is an obvious scalar type (bool, int, str, etc.) add those annotations as well. Also fixed two small bugs that popped up when sanity-checking with mypy. One in FortranCommon, where a return had been previously annotated to be a tuple of Action, which should be ActionBase - Action is the factory function, not the base class. The other was a typo in the error raised in _add_cppdefines - the message was formatted with the value of "define" which should have been "defines". Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'SCons/cpp.py')
-rw-r--r--SCons/cpp.py44
1 files changed, 22 insertions, 22 deletions
diff --git a/SCons/cpp.py b/SCons/cpp.py
index 144f49870..c9c9a70f0 100644
--- a/SCons/cpp.py
+++ b/SCons/cpp.py
@@ -180,7 +180,7 @@ del override
class FunctionEvaluator:
"""Handles delayed evaluation of a #define function call."""
- def __init__(self, name, args, expansion):
+ def __init__(self, name, args, expansion) -> None:
"""
Squirrels away the arguments and expansion value of a #define
macro function for later evaluation when we must actually expand
@@ -230,7 +230,7 @@ function_arg_separator = re.compile(r',\s*')
class PreProcessor:
"""The main workhorse class for handling C pre-processing."""
- def __init__(self, current=os.curdir, cpppath=(), dict={}, all=0, depth=-1):
+ def __init__(self, current=os.curdir, cpppath=(), dict={}, all: int=0, depth=-1) -> None:
global Table
cpppath = tuple(cpppath)
@@ -339,7 +339,7 @@ class PreProcessor:
# Dispatch table stack manipulation methods.
- def save(self):
+ def save(self) -> None:
"""
Pushes the current dispatch table on the stack and re-initializes
the current dispatch table to the default.
@@ -347,7 +347,7 @@ class PreProcessor:
self.stack.append(self.dispatch_table)
self.dispatch_table = self.default_table.copy()
- def restore(self):
+ def restore(self) -> None:
"""
Pops the previous dispatch table off the stack and makes it the
current one.
@@ -357,14 +357,14 @@ class PreProcessor:
# Utility methods.
- def do_nothing(self, t):
+ def do_nothing(self, t) -> None:
"""
Null method for when we explicitly want the action for a
specific preprocessor directive to do nothing.
"""
pass
- def scons_current_file(self, t):
+ def scons_current_file(self, t) -> None:
self.current_file = t[1]
def eval_expression(self, t):
@@ -381,7 +381,7 @@ class PreProcessor:
except (NameError, TypeError, SyntaxError):
return 0
- def initialize_result(self, fname):
+ def initialize_result(self, fname) -> None:
self.result = [fname]
def finalize_result(self, fname):
@@ -407,7 +407,7 @@ class PreProcessor:
# Start and stop processing include lines.
- def start_handling_includes(self, t=None):
+ def start_handling_includes(self, t=None) -> None:
"""
Causes the PreProcessor object to start processing #import,
#include and #include_next lines.
@@ -424,7 +424,7 @@ class PreProcessor:
for k in ('import', 'include', 'include_next', 'define', 'undef'):
d[k] = p[k]
- def stop_handling_includes(self, t=None):
+ def stop_handling_includes(self, t=None) -> None:
"""
Causes the PreProcessor object to stop processing #import,
#include and #include_next lines.
@@ -444,7 +444,7 @@ class PreProcessor:
# (Note that what actually gets called for a given directive at any
# point in time is really controlled by the dispatch_table.)
- def _do_if_else_condition(self, condition):
+ def _do_if_else_condition(self, condition) -> None:
"""
Common logic for evaluating the conditions on #if, #ifdef and
#ifndef lines.
@@ -460,25 +460,25 @@ class PreProcessor:
d['elif'] = self.do_elif
d['else'] = self.start_handling_includes
- def do_ifdef(self, t):
+ def do_ifdef(self, t) -> None:
"""
Default handling of a #ifdef line.
"""
self._do_if_else_condition(t[1] in self.cpp_namespace)
- def do_ifndef(self, t):
+ def do_ifndef(self, t) -> None:
"""
Default handling of a #ifndef line.
"""
self._do_if_else_condition(t[1] not in self.cpp_namespace)
- def do_if(self, t):
+ def do_if(self, t) -> None:
"""
Default handling of a #if line.
"""
self._do_if_else_condition(self.eval_expression(t))
- def do_elif(self, t):
+ def do_elif(self, t) -> None:
"""
Default handling of a #elif line.
"""
@@ -488,19 +488,19 @@ class PreProcessor:
d['elif'] = self.stop_handling_includes
d['else'] = self.stop_handling_includes
- def do_else(self, t):
+ def do_else(self, t) -> None:
"""
Default handling of a #else line.
"""
pass
- def do_endif(self, t):
+ def do_endif(self, t) -> None:
"""
Default handling of a #endif line.
"""
self.restore()
- def do_define(self, t):
+ def do_define(self, t) -> None:
"""
Default handling of a #define line.
"""
@@ -519,21 +519,21 @@ class PreProcessor:
else:
self.cpp_namespace[name] = expansion
- def do_undef(self, t):
+ def do_undef(self, t) -> None:
"""
Default handling of a #undef line.
"""
try: del self.cpp_namespace[t[1]]
except KeyError: pass
- def do_import(self, t):
+ def do_import(self, t) -> None:
"""
Default handling of a #import line.
"""
# XXX finish this -- maybe borrow/share logic from do_include()...?
pass
- def do_include(self, t):
+ def do_include(self, t) -> None:
"""
Default handling of a #include line.
"""
@@ -614,7 +614,7 @@ class PreProcessor:
return None
return (t[0], s[0], s[1:-1])
- def all_include(self, t):
+ def all_include(self, t) -> None:
"""
"""
self.result.append(self.resolve_include(t))
@@ -630,7 +630,7 @@ class DumbPreProcessor(PreProcessor):
an example of how the main PreProcessor class can be sub-classed
to tailor its behavior.
"""
- def __init__(self, *args, **kw):
+ def __init__(self, *args, **kw) -> None:
PreProcessor.__init__(self, *args, **kw)
d = self.default_table
for func in ['if', 'elif', 'else', 'endif', 'ifdef', 'ifndef']: