Skip to content

Commit 73935e4

Browse files
committed
Implement type hints for Node subclasses
1 parent 8fea6a2 commit 73935e4

File tree

11 files changed

+315
-283
lines changed

11 files changed

+315
-283
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
1515
From John Doe:
1616
- Whatever John Doe did.
1717

18+
From Thaddeus Crews:
19+
- Implement type hints for Node subclasses.
20+
1821
From William Deegan:
1922
- Fix SCons Docbook schema to work with lxml > 5
2023

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ DEVELOPMENT
7070

7171
- Introduce some unit tests for the file locking utility routines
7272

73+
- Implement type hints for Node subclasses.
74+
7375
Thanks to the following contributors listed below for their contributions to this release.
7476
==========================================================================================
7577
.. code-block:: text

SCons/Node/Alias.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@
2626
This creates a hash of global Aliases (dummy targets).
2727
"""
2828

29+
from __future__ import annotations
30+
2931
import collections
32+
from typing import TYPE_CHECKING
3033

3134
import SCons.Errors
3235
import SCons.Node
3336
import SCons.Util
3437
from SCons.Util import hash_signature
3538

39+
if TYPE_CHECKING:
40+
from SCons.Node.FS import Dir
41+
3642
class AliasNameSpace(collections.UserDict):
37-
def Alias(self, name, **kw):
43+
def Alias(self, name: str | Alias, **kw) -> Alias:
3844
if isinstance(name, SCons.Node.Alias.Alias):
3945
return name
4046
try:
@@ -44,7 +50,7 @@ def Alias(self, name, **kw):
4450
self[name] = a
4551
return a
4652

47-
def lookup(self, name, **kw):
53+
def lookup(self, name: str, **kw) -> Alias | None:
4854
try:
4955
return self[name]
5056
except KeyError:
@@ -66,13 +72,13 @@ class Alias(SCons.Node.Node):
6672
NodeInfo = AliasNodeInfo
6773
BuildInfo = AliasBuildInfo
6874

69-
def __init__(self, name) -> None:
75+
def __init__(self, name: str) -> None:
7076
super().__init__()
7177
self.name = name
7278
self.changed_since_last_build = 1
7379
self.store_info = 0
7480

75-
def str_for_display(self):
81+
def str_for_display(self) -> str:
7682
return '"' + self.__str__() + '"'
7783

7884
def __str__(self) -> str:
@@ -84,13 +90,13 @@ def make_ready(self) -> None:
8490
really_build = SCons.Node.Node.build
8591
is_up_to_date = SCons.Node.Node.children_are_up_to_date
8692

87-
def is_under(self, dir) -> bool:
93+
def is_under(self, dir: Dir) -> bool:
8894
# Make Alias nodes get built regardless of
8995
# what directory scons was run from. Alias nodes
9096
# are outside the filesystem:
9197
return True
9298

93-
def get_contents(self):
99+
def get_contents(self) -> str:
94100
"""The contents of an alias is the concatenation
95101
of the content signatures of all its sources."""
96102
childsigs = [n.get_csig() for n in self.children()]
@@ -120,7 +126,7 @@ def convert(self) -> None:
120126
self.reset_executor()
121127
self.build = self.really_build
122128

123-
def get_csig(self):
129+
def get_csig(self) -> str:
124130
"""
125131
Generate a node's content signature, the digested signature
126132
of its content.

0 commit comments

Comments
 (0)