Skip to content

Commit a0c180d

Browse files
authored
Initial fixes for Python 3.14 (#10384)
1 parent 1257474 commit a0c180d

File tree

6 files changed

+36
-52
lines changed

6 files changed

+36
-52
lines changed

pylint/checkers/base/name_checker/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def _assigns_typealias(node: nodes.NodeNG | None) -> bool:
648648
qname = inferred.qname()
649649
if qname == "typing.TypeAlias":
650650
return True
651-
if qname in {".Union", "builtins.UnionType"}:
651+
if qname in {".Union", "builtins.Union", "builtins.UnionType"}:
652652
# Union is a special case because it can be used as a type alias
653653
# or as a type annotation. We only want to check the former.
654654
assert node is not None

pylint/extensions/typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def _check_for_alternative_union_syntax(
354354
inferred = safe_infer(node)
355355
if not (
356356
(
357-
isinstance(inferred, nodes.FunctionDef)
357+
isinstance(inferred, (nodes.FunctionDef, nodes.ClassDef))
358358
and inferred.qname() in {"typing.Optional", "typing.Union"}
359359
)
360360
or (
@@ -538,7 +538,7 @@ def _broken_callable_location(self, node: nodes.Name | nodes.Attribute) -> bool:
538538
inferred_parent = safe_infer(parent_subscript.value)
539539
if not (
540540
(
541-
isinstance(inferred_parent, nodes.FunctionDef)
541+
isinstance(inferred_parent, (nodes.FunctionDef, nodes.ClassDef))
542542
and inferred_parent.qname() in {"typing.Optional", "typing.Union"}
543543
)
544544
or (

tests/functional/g/generic_alias/generic_alias_collections.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
collections.abc.Hashable[int] # [unsubscriptable-object]
6767
collections.abc.Sized[int] # [unsubscriptable-object]
6868

69-
# subscriptable with Python 3.9
70-
collections.abc.ByteString[int]
71-
7269

7370
# Missing implementation for 'collections.abc' derived classes
7471
class DerivedHashable(collections.abc.Hashable): # [abstract-method] # __hash__
@@ -117,14 +114,10 @@ class CustomImplementation(CustomAbstractCls2): # [abstract-method,abstract-met
117114
var_awaitable: collections.abc.Awaitable[int]
118115
var_contextmanager: contextlib.AbstractContextManager[int]
119116
var_pattern: re.Pattern[int]
120-
var_bytestring: collections.abc.ByteString
121117
var_hashable: collections.abc.Hashable
122118
var_sized: collections.abc.Sized
123119

124120
# Type annotation with unsubscriptable type
125121
var_int: int[int] # [unsubscriptable-object]
126122
var_hashable2: collections.abc.Hashable[int] # [unsubscriptable-object]
127123
var_sized2: collections.abc.Sized[int] # [unsubscriptable-object]
128-
129-
# subscriptable with Python 3.9
130-
var_bytestring2: collections.abc.ByteString[int]
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
unsubscriptable-object:66:0:66:24::Value 'collections.abc.Hashable' is unsubscriptable:UNDEFINED
22
unsubscriptable-object:67:0:67:21::Value 'collections.abc.Sized' is unsubscriptable:UNDEFINED
3-
abstract-method:74:0:74:21:DerivedHashable:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedHashable':INFERENCE
4-
abstract-method:77:0:77:21:DerivedIterable:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable':INFERENCE
5-
abstract-method:80:0:80:23:DerivedCollection:Method '__contains__' is abstract in class 'Container' but is not overridden in child class 'DerivedCollection':INFERENCE
6-
abstract-method:80:0:80:23:DerivedCollection:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedCollection':INFERENCE
7-
abstract-method:80:0:80:23:DerivedCollection:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedCollection':INFERENCE
8-
abstract-method:99:0:99:21:DerivedMultiple:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedMultiple':INFERENCE
9-
abstract-method:99:0:99:21:DerivedMultiple:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedMultiple':INFERENCE
10-
abstract-method:104:0:104:24:CustomAbstractCls2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
11-
abstract-method:104:0:104:24:CustomAbstractCls2:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
12-
abstract-method:106:0:106:26:CustomImplementation:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomImplementation':INFERENCE
13-
abstract-method:106:0:106:26:CustomImplementation:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomImplementation':INFERENCE
14-
unsubscriptable-object:125:9:125:12::Value 'int' is unsubscriptable:UNDEFINED
15-
unsubscriptable-object:126:15:126:39::Value 'collections.abc.Hashable' is unsubscriptable:UNDEFINED
16-
unsubscriptable-object:127:12:127:33::Value 'collections.abc.Sized' is unsubscriptable:UNDEFINED
3+
abstract-method:71:0:71:21:DerivedHashable:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedHashable':INFERENCE
4+
abstract-method:74:0:74:21:DerivedIterable:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable':INFERENCE
5+
abstract-method:77:0:77:23:DerivedCollection:Method '__contains__' is abstract in class 'Container' but is not overridden in child class 'DerivedCollection':INFERENCE
6+
abstract-method:77:0:77:23:DerivedCollection:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedCollection':INFERENCE
7+
abstract-method:77:0:77:23:DerivedCollection:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedCollection':INFERENCE
8+
abstract-method:96:0:96:21:DerivedMultiple:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedMultiple':INFERENCE
9+
abstract-method:96:0:96:21:DerivedMultiple:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedMultiple':INFERENCE
10+
abstract-method:101:0:101:24:CustomAbstractCls2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
11+
abstract-method:101:0:101:24:CustomAbstractCls2:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
12+
abstract-method:103:0:103:26:CustomImplementation:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomImplementation':INFERENCE
13+
abstract-method:103:0:103:26:CustomImplementation:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomImplementation':INFERENCE
14+
unsubscriptable-object:121:9:121:12::Value 'int' is unsubscriptable:UNDEFINED
15+
unsubscriptable-object:122:15:122:39::Value 'collections.abc.Hashable' is unsubscriptable:UNDEFINED
16+
unsubscriptable-object:123:12:123:33::Value 'collections.abc.Sized' is unsubscriptable:UNDEFINED

tests/functional/g/generic_alias/generic_alias_typing.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,11 @@
5555
# re
5656
typing.Pattern[str]
5757
typing.Match[str]
58-
typing.re.Pattern[str]
59-
typing.re.Match[str]
6058

6159

6260
# unsubscriptable types
63-
typing.ByteString
6461
typing.Hashable
6562
typing.Sized
66-
typing.ByteString[int] # [unsubscriptable-object]
6763
typing.Hashable[int] # [unsubscriptable-object]
6864
typing.Sized[int] # [unsubscriptable-object]
6965

@@ -129,14 +125,11 @@ class DerivedIterable2(typing.Iterable): # [abstract-method] # __iter__
129125
var_awaitable: typing.Awaitable[int]
130126
var_contextmanager: typing.ContextManager[int]
131127
var_pattern: typing.Pattern[int]
132-
var_pattern2: typing.re.Pattern[int]
133-
var_bytestring: typing.ByteString
134128
var_hashable: typing.Hashable
135129
var_sized: typing.Sized
136130

137131
# Type annotation with unsubscriptable type
138132
var_int: int[int] # [unsubscriptable-object]
139-
var_bytestring2: typing.ByteString[int] # [unsubscriptable-object]
140133
var_hashable2: typing.Hashable[int] # [unsubscriptable-object]
141134
var_sized2: typing.Sized[int] # [unsubscriptable-object]
142135

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
unsubscriptable-object:66:0:66:17::Value 'typing.ByteString' is unsubscriptable:UNDEFINED
2-
unsubscriptable-object:67:0:67:15::Value 'typing.Hashable' is unsubscriptable:UNDEFINED
3-
unsubscriptable-object:68:0:68:12::Value 'typing.Sized' is unsubscriptable:UNDEFINED
4-
abstract-method:72:0:72:21:DerivedHashable:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedHashable':INFERENCE
5-
abstract-method:75:0:75:21:DerivedIterable:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable':INFERENCE
6-
abstract-method:78:0:78:23:DerivedCollection:Method '__contains__' is abstract in class 'Container' but is not overridden in child class 'DerivedCollection':INFERENCE
7-
abstract-method:78:0:78:23:DerivedCollection:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedCollection':INFERENCE
8-
abstract-method:78:0:78:23:DerivedCollection:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedCollection':INFERENCE
9-
abstract-method:100:0:100:21:DerivedMultiple:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedMultiple':INFERENCE
10-
abstract-method:100:0:100:21:DerivedMultiple:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedMultiple':INFERENCE
11-
abstract-method:105:0:105:24:CustomAbstractCls2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
12-
abstract-method:105:0:105:24:CustomAbstractCls2:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
13-
abstract-method:107:0:107:26:CustomImplementation:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomImplementation':INFERENCE
14-
abstract-method:107:0:107:26:CustomImplementation:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomImplementation':INFERENCE
15-
abstract-method:118:0:118:22:DerivedIterable2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable2':INFERENCE
16-
unsubscriptable-object:138:9:138:12::Value 'int' is unsubscriptable:UNDEFINED
17-
unsubscriptable-object:139:17:139:34::Value 'typing.ByteString' is unsubscriptable:UNDEFINED
18-
unsubscriptable-object:140:15:140:30::Value 'typing.Hashable' is unsubscriptable:UNDEFINED
19-
unsubscriptable-object:141:12:141:24::Value 'typing.Sized' is unsubscriptable:UNDEFINED
20-
unsubscriptable-object:148:8:148:9::Value 'A' is unsubscriptable:UNDEFINED
21-
unsubscriptable-object:150:8:150:9:B:Value 'A' is unsubscriptable:UNDEFINED
1+
unsubscriptable-object:63:0:63:15::Value 'typing.Hashable' is unsubscriptable:UNDEFINED
2+
unsubscriptable-object:64:0:64:12::Value 'typing.Sized' is unsubscriptable:UNDEFINED
3+
abstract-method:68:0:68:21:DerivedHashable:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedHashable':INFERENCE
4+
abstract-method:71:0:71:21:DerivedIterable:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable':INFERENCE
5+
abstract-method:74:0:74:23:DerivedCollection:Method '__contains__' is abstract in class 'Container' but is not overridden in child class 'DerivedCollection':INFERENCE
6+
abstract-method:74:0:74:23:DerivedCollection:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedCollection':INFERENCE
7+
abstract-method:74:0:74:23:DerivedCollection:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedCollection':INFERENCE
8+
abstract-method:96:0:96:21:DerivedMultiple:Method '__hash__' is abstract in class 'Hashable' but is not overridden in child class 'DerivedMultiple':INFERENCE
9+
abstract-method:96:0:96:21:DerivedMultiple:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'DerivedMultiple':INFERENCE
10+
abstract-method:101:0:101:24:CustomAbstractCls2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
11+
abstract-method:101:0:101:24:CustomAbstractCls2:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomAbstractCls2':INFERENCE
12+
abstract-method:103:0:103:26:CustomImplementation:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'CustomImplementation':INFERENCE
13+
abstract-method:103:0:103:26:CustomImplementation:Method '__len__' is abstract in class 'Sized' but is not overridden in child class 'CustomImplementation':INFERENCE
14+
abstract-method:114:0:114:22:DerivedIterable2:Method '__iter__' is abstract in class 'Iterable' but is not overridden in child class 'DerivedIterable2':INFERENCE
15+
unsubscriptable-object:132:9:132:12::Value 'int' is unsubscriptable:UNDEFINED
16+
unsubscriptable-object:133:15:133:30::Value 'typing.Hashable' is unsubscriptable:UNDEFINED
17+
unsubscriptable-object:134:12:134:24::Value 'typing.Sized' is unsubscriptable:UNDEFINED
18+
unsubscriptable-object:141:8:141:9::Value 'A' is unsubscriptable:UNDEFINED
19+
unsubscriptable-object:143:8:143:9:B:Value 'A' is unsubscriptable:UNDEFINED

0 commit comments

Comments
 (0)