Skip to content

Commit 1a21836

Browse files
authored
TYP: io (#36120)
1 parent b8e4a09 commit 1a21836

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pandas/io/excel/_util.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from pandas.compat._optional import import_optional_dependency
24

35
from pandas.core.dtypes.common import is_integer, is_list_like
@@ -56,7 +58,7 @@ def get_writer(engine_name):
5658
raise ValueError(f"No Excel writer '{engine_name}'") from err
5759

5860

59-
def _excel2num(x):
61+
def _excel2num(x: str) -> int:
6062
"""
6163
Convert Excel column name like 'AB' to 0-based column index.
6264
@@ -88,7 +90,7 @@ def _excel2num(x):
8890
return index - 1
8991

9092

91-
def _range2cols(areas):
93+
def _range2cols(areas: str) -> List[int]:
9294
"""
9395
Convert comma separated list of column names and ranges to indices.
9496
@@ -109,12 +111,12 @@ def _range2cols(areas):
109111
>>> _range2cols('A,C,Z:AB')
110112
[0, 2, 25, 26, 27]
111113
"""
112-
cols = []
114+
cols: List[int] = []
113115

114116
for rng in areas.split(","):
115117
if ":" in rng:
116-
rng = rng.split(":")
117-
cols.extend(range(_excel2num(rng[0]), _excel2num(rng[1]) + 1))
118+
rngs = rng.split(":")
119+
cols.extend(range(_excel2num(rngs[0]), _excel2num(rngs[1]) + 1))
118120
else:
119121
cols.append(_excel2num(rng))
120122

pandas/io/formats/css.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import re
6+
from typing import Optional
67
import warnings
78

89

@@ -93,6 +94,7 @@ def __call__(self, declarations_str, inherited=None):
9394
props[prop] = val
9495

9596
# 2. resolve relative font size
97+
font_size: Optional[float]
9698
if props.get("font-size"):
9799
if "font-size" in inherited:
98100
em_pt = inherited["font-size"]
@@ -173,10 +175,11 @@ def _error():
173175
warnings.warn(f"Unhandled size: {repr(in_val)}", CSSWarning)
174176
return self.size_to_pt("1!!default", conversions=conversions)
175177

176-
try:
177-
val, unit = re.match(r"^(\S*?)([a-zA-Z%!].*)", in_val).groups()
178-
except AttributeError:
178+
match = re.match(r"^(\S*?)([a-zA-Z%!].*)", in_val)
179+
if match is None:
179180
return _error()
181+
182+
val, unit = match.groups()
180183
if val == "":
181184
# hack for 'large' etc.
182185
val = 1

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ check_untyped_defs=False
279279
[mypy-pandas.io.formats.console]
280280
check_untyped_defs=False
281281

282-
[mypy-pandas.io.formats.css]
283-
check_untyped_defs=False
284-
285282
[mypy-pandas.io.formats.csvs]
286283
check_untyped_defs=False
287284

0 commit comments

Comments
 (0)