Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 0854a95

Browse files
lordmauvesambhav
authored andcommitted
Workaround mypy un-ignoreable error in Py35
1 parent c987558 commit 0854a95

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
File renamed without changes.

src/tests/test_definitions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ def test_all_interpreters(test_case):
3636
)
3737
def test_fstrings():
3838
"""Run the f-string test case under Python 3.6+ only."""
39+
# When run under Python 3.5, mypy reports a parse error for the test file,
40+
# because Python 3.5 doesn't support f-strings. It does not support
41+
# ignoring parse errors.
42+
#
43+
# To work around this, we put our code in a file that mypy cannot see. This
44+
# code reveals it to Python.
45+
from . import test_cases
46+
import importlib.machinery
47+
test_cases_dir = test_cases.__path__[0]
48+
loader = sys.path_importer_cache[test_cases_dir]
49+
loader._loaders.append(('.py36', importlib.machinery.SourceFileLoader))
50+
3951
run_case('fstrings')
4052

4153

@@ -46,10 +58,8 @@ def run_case(test_case):
4658
locals=locals(),
4759
fromlist=['expectation'],
4860
level=1)
49-
test_case_dir = os.path.normcase(os.path.dirname(__file__))
50-
test_case_file = os.path.join(test_case_dir,
51-
'test_cases',
52-
test_case + '.py')
61+
62+
test_case_file = case_module.__file__
5363
results = list(check([test_case_file],
5464
select=set(ErrorRegistry.get_error_codes()),
5565
ignore_decorators=re.compile(

0 commit comments

Comments
 (0)