Skip to content

Commit d5af6be

Browse files
authored
Clean up deprecated ast.Constant aliases (#14397)
Add `__new__`, remove fields, mark deprecated `Constant` fields as such.
1 parent c1299e3 commit d5af6be

File tree

6 files changed

+22
-38
lines changed

6 files changed

+22
-38
lines changed

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ tkinter.tix.TkVersion
163163
# because it's not an ABC that makes any sense and was deprecated in 3.12
164164
_collections_abc.ByteString
165165

166-
ast.Bytes.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
167-
ast.Ellipsis.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
168-
ast.NameConstant.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
169-
ast.Num.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
170-
ast.Str.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
166+
ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any
171167

172168
_?hashlib.scrypt # Raises TypeError if salt, n, r or p are None
173169

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ tkinter.tix.TkVersion
126126
# because it's not an ABC that makes any sense and was deprecated in 3.12
127127
_collections_abc.ByteString
128128

129-
ast.Bytes.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
130-
ast.Ellipsis.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
131-
ast.NameConstant.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
132-
ast.Num.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
133-
ast.Str.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
129+
ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any
134130

135131
_?hashlib.scrypt # Raises TypeError if salt, n, r or p are None
136132

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ tkinter.tix.TkVersion
111111
# because it's not an ABC that makes any sense and was deprecated in 3.12
112112
_collections_abc.ByteString
113113

114-
ast.Bytes.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
115-
ast.Ellipsis.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
116-
ast.NameConstant.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
117-
ast.Num.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
118-
ast.Str.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
114+
ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any
119115

120116
_?hashlib.scrypt # Raises TypeError if salt, n, r or p are None
121117

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ typing(_extensions)?\.IO\.writelines
7272
# because it's not an ABC that makes any sense and was deprecated in 3.12
7373
_collections_abc.ByteString
7474

75-
ast.Bytes.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
76-
ast.Ellipsis.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
77-
ast.NameConstant.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
78-
ast.Num.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
79-
ast.Str.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
75+
ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any
8076

8177
_?hashlib.scrypt # Raises TypeError if salt, n, r or p are None
8278

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ tkinter.tix.TkVersion
110110
# because it's not an ABC that makes any sense and was deprecated in 3.12
111111
_collections_abc.ByteString
112112

113-
ast.Bytes.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
114-
ast.Ellipsis.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
115-
ast.NameConstant.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
116-
ast.Num.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
117-
ast.Str.__new__ # runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
113+
ast.Ellipsis.__new__ # Implementation has *args, but shouldn't allow any
118114

119115
_?hashlib.scrypt # Raises TypeError if salt, n, r or p are None
120116

stdlib/ast.pyi

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,16 @@ class Constant(expr):
10961096
kind: str | None
10971097
if sys.version_info < (3, 14):
10981098
# Aliases for value, for backwards compatibility
1099-
s: _ConstantValue
1100-
n: _ConstantValue
1099+
@deprecated("Will be removed in Python 3.14; use value instead")
1100+
@property
1101+
def n(self) -> _ConstantValue: ...
1102+
@n.setter
1103+
def n(self, value: _ConstantValue) -> None: ...
1104+
@deprecated("Will be removed in Python 3.14; use value instead")
1105+
@property
1106+
def s(self) -> _ConstantValue: ...
1107+
@s.setter
1108+
def s(self, value: _ConstantValue) -> None: ...
11011109

11021110
def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
11031111

@@ -1696,27 +1704,23 @@ class _ABC(type):
16961704
if sys.version_info < (3, 14):
16971705
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
16981706
class Num(Constant, metaclass=_ABC):
1699-
value: int | float | complex
1700-
# Aliases for value, for backwards compatibility
1701-
n: int | float | complex
1707+
def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
17021708

17031709
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
17041710
class Str(Constant, metaclass=_ABC):
1705-
value: str
1706-
# Aliases for value, for backwards compatibility
1707-
s: str
1711+
def __new__(cls, s: str, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
17081712

17091713
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
17101714
class Bytes(Constant, metaclass=_ABC):
1711-
value: bytes
1712-
# Aliases for value, for backwards compatibility
1713-
s: bytes
1715+
def __new__(cls, s: bytes, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
17141716

17151717
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
1716-
class NameConstant(Constant, metaclass=_ABC): ...
1718+
class NameConstant(Constant, metaclass=_ABC):
1719+
def __new__(cls, value: _ConstantValue, kind: str | None, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
17171720

17181721
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
1719-
class Ellipsis(Constant, metaclass=_ABC): ...
1722+
class Ellipsis(Constant, metaclass=_ABC):
1723+
def __new__(cls, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
17201724

17211725
# everything below here is defined in ast.py
17221726

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy