Skip to content

Commit ebee0d9

Browse files
committed
Fix bad typing in Action.py
Two methods had added type hints for the new override parameter, but not got them right: it's a dict if defined, else None. Corrected this and made a few other minor tweaks. Signed-off-by: Mats Wichmann <[email protected]>
1 parent e48e447 commit ebee0d9

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
7474
Fixes #3529.
7575
- Clarify/fix documentation of Scanners in User Guide and Manpage.
7676
Fixes #4468.
77+
- Fix bad typing in Action.py: process() and strfunction().
7778

7879

7980
RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700

SCons/Action.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
from abc import ABC, abstractmethod
110110
from collections import OrderedDict
111111
from subprocess import DEVNULL, PIPE
112+
from typing import List, Optional, Tuple
112113

113114
import SCons.Debug
114115
import SCons.Errors
@@ -117,7 +118,7 @@
117118

118119
# we use these a lot, so try to optimize them
119120
from SCons.Debug import logInstanceCreation
120-
from SCons.Subst import SUBST_SIG, SUBST_RAW
121+
from SCons.Subst import SUBST_CMD, SUBST_RAW, SUBST_SIG
121122
from SCons.Util import is_String, is_List
122123

123124
class _null:
@@ -127,13 +128,10 @@ class _null:
127128
execute_actions = True
128129
print_actions_presub = False
129130

130-
# Use pickle protocol 1 when pickling functions for signature
131-
# otherwise python3 and python2 will yield different pickles
132-
# for the same object.
133-
# This is due to default being 1 for python 2.7, and 3 for 3.x
134-
# TODO: We can roll this forward to 2 (if it has value), but not
135-
# before a deprecation cycle as the sconsigns will change
136-
ACTION_SIGNATURE_PICKLE_PROTOCOL = 1
131+
# Use pickle protocol 4 when pickling functions for signature.
132+
# This is the common format since Python 3.4
133+
# TODO: use is commented out as not stable since 2017: e0bc3a04d5. Drop?
134+
# ACTION_SIGNATURE_PICKLE_PROTOCOL = 4
137135

138136

139137
def rfile(n):
@@ -448,7 +446,7 @@ def _do_create_action(act, kw):
448446
return act
449447

450448
if is_String(act):
451-
var=SCons.Util.get_environment_var(act)
449+
var = SCons.Util.get_environment_var(act)
452450
if var:
453451
# This looks like a string that is purely an Environment
454452
# variable reference, like "$FOO" or "${FOO}". We do
@@ -1010,18 +1008,18 @@ def __str__(self) -> str:
10101008
return ' '.join(map(str, self.cmd_list))
10111009
return str(self.cmd_list)
10121010

1013-
def process(self, target, source, env, executor=None, overrides: bool=False):
1011+
def process(self, target, source, env, executor=None, overrides: Optional[dict] = None) -> Tuple[List, bool, bool]:
10141012
if executor:
1015-
result = env.subst_list(self.cmd_list, 0, executor=executor, overrides=overrides)
1013+
result = env.subst_list(self.cmd_list, SUBST_CMD, executor=executor, overrides=overrides)
10161014
else:
1017-
result = env.subst_list(self.cmd_list, 0, target, source, overrides=overrides)
1018-
silent = None
1019-
ignore = None
1015+
result = env.subst_list(self.cmd_list, SUBST_CMD, target, source, overrides=overrides)
1016+
silent = False
1017+
ignore = False
10201018
while True:
10211019
try: c = result[0][0][0]
10221020
except IndexError: c = None
1023-
if c == '@': silent = 1
1024-
elif c == '-': ignore = 1
1021+
if c == '@': silent = True
1022+
elif c == '-': ignore = True
10251023
else: break
10261024
result[0][0] = result[0][0][1:]
10271025
try:
@@ -1031,7 +1029,7 @@ def process(self, target, source, env, executor=None, overrides: bool=False):
10311029
pass
10321030
return result, ignore, silent
10331031

1034-
def strfunction(self, target, source, env, executor=None, overrides: bool=False):
1032+
def strfunction(self, target, source, env, executor=None, overrides: Optional[dict] = None) -> str:
10351033
if self.cmdstr is None:
10361034
return None
10371035
if self.cmdstr is not _null:
@@ -1256,8 +1254,7 @@ def __str__(self) -> str:
12561254
try:
12571255
env = self.presub_env
12581256
except AttributeError:
1259-
env = None
1260-
if env is None:
1257+
import SCons.Defaults # pylint: disable=import-outside-toplevel
12611258
env = SCons.Defaults.DefaultEnvironment()
12621259
act = self._generate([], [], env, 1)
12631260
return str(act)

0 commit comments

Comments
 (0)