File tree Expand file tree Collapse file tree 3 files changed +16
-27
lines changed
Expand file tree Collapse file tree 3 files changed +16
-27
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ dev = [
4949 ' urllib3 >= 2.0' ,
5050 " pytest >= 7.0, < 9" ,
5151 ' pytest-mypy-plugins >= 3.2.0' ,
52- ' pytest-revealtype-injector >= 0.7.1 ' ,
52+ ' pytest-revealtype-injector >= 0.8.0 ' ,
5353 ' lxml >= 5.0' ,
5454 ' rnc2rng' ,
5555 ' hypothesis >= 6.127.7' , # HypothesisWorks/hypothesis#4269
@@ -89,7 +89,7 @@ rt-test = [
8989 " hypothesis == 6.148.8" ,
9090 " tzdata" ,
9191 " pytest >= 7.0, < 9" ,
92- " pytest-revealtype-injector == 0.7.1 " ,
92+ " pytest-revealtype-injector == 0.8.0 " ,
9393 " rnc2rng == 2.7.0" ,
9494 {include-group = " mypy" },
9595 {include-group = " pyright" },
Original file line number Diff line number Diff line change 3838else :
3939 from typing_extensions import reveal_type
4040
41- # See mypy.ini in testsuite for explanation
42- TC_HONORS_REVERSED = True
43-
4441
4542class TestBasicBehavior :
4643 def test_sequence_read (self , xml2_root : _Element ) -> None :
@@ -58,16 +55,6 @@ def test_sequence_read(self, xml2_root: _Element) -> None:
5855 assert elem .index (item ) == 0
5956 del itr , item
6057
61- if TC_HONORS_REVERSED :
62- rev = reversed (elem )
63- else :
64- rev = elem .__reversed__ ()
65- reveal_type (rev )
66- item = next (rev )
67- reveal_type (item )
68- assert elem .index (item ) == length - 1
69- del rev , item
70-
7158 for sub in elem :
7259 reveal_type (sub )
7360
@@ -81,6 +68,20 @@ def test_sequence_read(self, xml2_root: _Element) -> None:
8168
8269 del elem , subelem
8370
71+ # mypy and ty don't support magic method and always treat
72+ # reversed(...) as `reversed` object
73+ @pytest .mark .notypechecker ("mypy" , "ty" )
74+ def test_reversed_seq_read_1 (self , xml2_root : _Element ) -> None :
75+ rev = reversed (xml2_root )
76+ reveal_type (rev )
77+ reveal_type (list (rev ))
78+
79+ @pytest .mark .onlytypechecker ("mypy" , "ty" )
80+ def test_reversed_seq_read_2 (self , xml2_root : _Element ) -> None :
81+ rev = xml2_root .__reversed__ ()
82+ reveal_type (rev )
83+ reveal_type (list (rev ))
84+
8485 def test_sequence_modify (self , xml2_root : _Element ) -> None :
8586 elem = deepcopy (xml2_root )
8687
Original file line number Diff line number Diff line change @@ -20,15 +20,3 @@ ignore_missing_imports = True
2020# statements frequently used in tests.
2121
2222disable_error_code = func-returns-value
23-
24- # In some other cases, tests have to be altered in
25- # alternative form for mypy to be functional.
26- #
27- # -- TC_HONORS_REVERSED
28- # Mypy thinks reversed(T) always produce reversed object,
29- # ignoring annotation completely.
30- # Mypy groks T.__reversed__() however, just not honoring
31- # the fact that reversed(T) is T.__reversed__() if
32- # available.
33-
34- always_false = TC_HONORS_REVERSED
You can’t perform that action at this time.
0 commit comments