Skip to content

Commit bb65ad8

Browse files
properly type the optional lxml dep
1 parent f98aa58 commit bb65ad8

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

mypy/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from mypy.version import __version__
2727

2828
try:
29-
from lxml import etree # type: ignore[import-untyped]
29+
from lxml import etree
3030

3131
LXML_INSTALLED = True
3232
except ImportError:

mypy/test/testcheck.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
import tempfile
99
from pathlib import Path
10+
from types import ModuleType
11+
from typing import Optional
1012

1113
from mypy import build
1214
from mypy.errors import CompileError
@@ -25,8 +27,9 @@
2527
)
2628
from mypy.test.update_data import update_testcase_output
2729

30+
lxml: Optional[ModuleType] #lxml is an optional dependency
2831
try:
29-
import lxml # type: ignore[import-untyped]
32+
import lxml
3033
except ImportError:
3134
lxml = None
3235

mypy/test/testcmdline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import re
1111
import subprocess
1212
import sys
13+
from types import ModuleType
14+
from typing import Optional
1315

1416
from mypy.test.config import PREFIX, test_temp_dir
1517
from mypy.test.data import DataDrivenTestCase, DataSuite
@@ -19,8 +21,9 @@
1921
normalize_error_messages,
2022
)
2123

24+
lxml: Optional[ModuleType] #lxml is an optional dependency
2225
try:
23-
import lxml # type: ignore[import-untyped]
26+
import lxml
2427
except ImportError:
2528
lxml = None
2629

mypy/test/testreports.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
from __future__ import annotations
44

55
import textwrap
6+
from types import ModuleType
7+
from typing import Optional
8+
69

710
from mypy.report import CoberturaPackage, get_line_rate
811
from mypy.test.helpers import Suite, assert_equal
912

13+
lxml: Optional[ModuleType] #lxml is an optional dependency
1014
try:
11-
import lxml # type: ignore[import-untyped]
15+
import lxml
1216
except ImportError:
1317
lxml = None
1418

@@ -23,7 +27,7 @@ def test_get_line_rate(self) -> None:
2327

2428
@pytest.mark.skipif(lxml is None, reason="Cannot import lxml. Is it installed?")
2529
def test_as_xml(self) -> None:
26-
import lxml.etree as etree # type: ignore[import-untyped]
30+
import lxml.etree as etree
2731

2832
cobertura_package = CoberturaPackage("foobar")
2933
cobertura_package.covered_lines = 21

0 commit comments

Comments
 (0)