Skip to content

Commit 9288bd2

Browse files
committed
typing types have the __args__ property. Close pylint-dev/pylint#2419
1 parent 393a8a7 commit 9288bd2

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ What's New in astroid 2.2.0?
66
============================
77
Release Date: TBA
88

9+
10+
* ``typing`` types have the `__args__` property. Close PyCQA/pylint#2419
11+
912
* Fix a bug where an Attribute used as a base class was triggering a crash
1013

1114
Close #626

astroid/brain/brain_typing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class Meta(type):
2525
def __getitem__(self, item):
2626
return self
2727
28+
@property
29+
def __args__(self):
30+
return ()
31+
2832
class {0}(metaclass=Meta):
2933
pass
3034
"""

astroid/tests/unittest_brain.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,17 @@ def test_typing_types(self):
965965
inferred = next(node.infer())
966966
self.assertIsInstance(inferred, nodes.ClassDef, node.as_string())
967967

968+
def test_has_dunder_args(self):
969+
ast_node = builder.extract_node(
970+
"""
971+
from typing import Union
972+
NumericTypes = Union[int, float]
973+
NumericTypes.__args__ #@
974+
"""
975+
)
976+
inferred = next(ast_node.infer())
977+
assert isinstance(inferred, nodes.Tuple)
978+
968979

969980
class ReBrainTest(unittest.TestCase):
970981
def test_regex_flags(self):

0 commit comments

Comments
 (0)