Skip to content

Commit c716ff1

Browse files
committed
Merge 'upstream/main' into concatenate/ellipsis
2 parents 2e5fc74 + b6c0558 commit c716ff1

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

.github/workflows/third_party.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
strategy:
187187
fail-fast: false
188188
matrix:
189-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.10"]
189+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
190190
runs-on: ubuntu-latest
191191
timeout-minutes: 60
192192
steps:

pyproject.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ select = [
8181
"W",
8282
]
8383

84-
# Ignore various "modernization" rules that tell you off for importing/using
85-
# deprecated things from the typing module, etc.
86-
ignore = ["UP006", "UP007", "UP013", "UP014", "UP019", "UP035", "UP038"]
84+
ignore = [
85+
# Ignore various "modernization" rules that tell you off for importing/using
86+
# deprecated things from the typing module, etc.
87+
"UP006",
88+
"UP007",
89+
"UP013",
90+
"UP014",
91+
"UP019",
92+
"UP035",
93+
"UP038",
94+
# Not relevant here
95+
"RUF012",
96+
]
8797

8898
[tool.ruff.lint.per-file-ignores]
8999
"!src/typing_extensions.py" = [

src/test_typing_extensions.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import importlib
1010
import inspect
1111
import io
12+
import itertools
1213
import pickle
1314
import re
1415
import subprocess
@@ -7751,6 +7752,71 @@ def f(x: int):
77517752
self.assertEqual(get_annotations(f), {"x": str})
77527753

77537754

7755+
class TestGetAnnotationsMetaclasses(BaseTestCase):
7756+
def test_annotated_meta(self):
7757+
class Meta(type):
7758+
a: int
7759+
7760+
class X(metaclass=Meta):
7761+
pass
7762+
7763+
class Y(metaclass=Meta):
7764+
b: float
7765+
7766+
self.assertEqual(get_annotations(Meta), {"a": int})
7767+
self.assertEqual(get_annotations(X), {})
7768+
self.assertEqual(get_annotations(Y), {"b": float})
7769+
7770+
def test_unannotated_meta(self):
7771+
class Meta(type): pass
7772+
7773+
class X(metaclass=Meta):
7774+
a: str
7775+
7776+
class Y(X): pass
7777+
7778+
self.assertEqual(get_annotations(Meta), {})
7779+
self.assertEqual(get_annotations(Y), {})
7780+
self.assertEqual(get_annotations(X), {"a": str})
7781+
7782+
def test_ordering(self):
7783+
# Based on a sample by David Ellis
7784+
# https://discuss.python.org/t/pep-749-implementing-pep-649/54974/38
7785+
7786+
def make_classes():
7787+
class Meta(type):
7788+
a: int
7789+
expected_annotations = {"a": int}
7790+
7791+
class A(type, metaclass=Meta):
7792+
b: float
7793+
expected_annotations = {"b": float}
7794+
7795+
class B(metaclass=A):
7796+
c: str
7797+
expected_annotations = {"c": str}
7798+
7799+
class C(B):
7800+
expected_annotations = {}
7801+
7802+
class D(metaclass=Meta):
7803+
expected_annotations = {}
7804+
7805+
return Meta, A, B, C, D
7806+
7807+
classes = make_classes()
7808+
class_count = len(classes)
7809+
for order in itertools.permutations(range(class_count), class_count):
7810+
names = ", ".join(classes[i].__name__ for i in order)
7811+
with self.subTest(names=names):
7812+
classes = make_classes() # Regenerate classes
7813+
for i in order:
7814+
get_annotations(classes[i])
7815+
for c in classes:
7816+
with self.subTest(c=c):
7817+
self.assertEqual(get_annotations(c), c.expected_annotations)
7818+
7819+
77547820
@skipIf(STRINGIZED_ANNOTATIONS_PEP_695 is None, "PEP 695 has yet to be")
77557821
class TestGetAnnotationsWithPEP695(BaseTestCase):
77567822
@classmethod

0 commit comments

Comments
 (0)