Skip to content

Commit d171a18

Browse files
authored
Add regression test for #1124 (#1364)
1 parent 3047277 commit d171a18

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

astroid/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
PY310_PLUS = sys.version_info >= (3, 10)
99
BUILTINS = "builtins" # TODO Remove in 2.8
1010

11+
WIN32 = sys.platform == "win32"
12+
1113

1214
class Context(enum.Enum):
1315
Load = 1

tests/unittest_scoped_nodes.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343

4444
import pytest
4545

46-
from astroid import MANAGER, builder, nodes, objects, test_utils, util
46+
from astroid import MANAGER, builder, nodes, objects, parse, test_utils, util
4747
from astroid.bases import BoundMethod, Generator, Instance, UnboundMethod
48-
from astroid.const import PY38_PLUS
48+
from astroid.const import PY38_PLUS, PY310_PLUS, WIN32
4949
from astroid.exceptions import (
5050
AttributeInferenceError,
5151
DuplicateBasesError,
@@ -1670,6 +1670,49 @@ class B(A[T], A[T]): ...
16701670
with self.assertRaises(DuplicateBasesError):
16711671
cls.mro()
16721672

1673+
@test_utils.require_version(minver="3.7")
1674+
def test_mro_typing_extensions(self):
1675+
"""Regression test for mro() inference on typing_extesnions.
1676+
1677+
Regression reported in:
1678+
https://github.com/PyCQA/astroid/issues/1124
1679+
"""
1680+
module = parse(
1681+
"""
1682+
import abc
1683+
import typing
1684+
import dataclasses
1685+
1686+
import typing_extensions
1687+
1688+
T = typing.TypeVar("T")
1689+
1690+
class MyProtocol(typing_extensions.Protocol): pass
1691+
class EarlyBase(typing.Generic[T], MyProtocol): pass
1692+
class Base(EarlyBase[T], abc.ABC): pass
1693+
class Final(Base[object]): pass
1694+
"""
1695+
)
1696+
class_names = [
1697+
"ABC",
1698+
"Base",
1699+
"EarlyBase",
1700+
"Final",
1701+
"Generic",
1702+
"MyProtocol",
1703+
"Protocol",
1704+
"object",
1705+
]
1706+
if not PY38_PLUS:
1707+
class_names.pop(-2)
1708+
# typing_extensions is not installed on this combination of version
1709+
# and platform
1710+
if PY310_PLUS and WIN32:
1711+
class_names.pop(-2)
1712+
1713+
final_def = module.body[-1]
1714+
self.assertEqual(class_names, sorted(i.name for i in final_def.mro()))
1715+
16731716
def test_generator_from_infer_call_result_parent(self) -> None:
16741717
func = builder.extract_node(
16751718
"""

0 commit comments

Comments
 (0)