Skip to content

Commit 8c22223

Browse files
committed
ROB: _font: Always returns a FontDescriptor; fix typing
mypy complained that the .from_font_resource method's return type is Optional[FontDescriptor]. Change the code to not confuse mypy.
1 parent b6fff56 commit 8c22223

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pypdf/_font.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from dataclasses import dataclass, field
2-
from typing import Optional
32

43
from pypdf.generic import DictionaryObject
54

@@ -29,10 +28,10 @@ class FontDescriptor:
2928
character_widths: dict[str, int] = field(default_factory=dict)
3029

3130
@classmethod
32-
def from_font_resource(cls, pdf_font_dict: DictionaryObject) -> "Optional[FontDescriptor]":
31+
def from_font_resource(cls, pdf_font_dict: DictionaryObject) -> "FontDescriptor":
3332
from pypdf._codecs.core_fontmetrics import CORE_FONT_METRICS # noqa: PLC0415
3433
# Prioritize information from the PDF font dictionary
3534
font_name = pdf_font_dict.get("/BaseFont", "Unknown")
3635
if font_name[1:] in CORE_FONT_METRICS:
37-
return CORE_FONT_METRICS.get(font_name[1:])
36+
return CORE_FONT_METRICS[font_name[1:]]
3837
return cls(name=font_name)

0 commit comments

Comments
 (0)