Merge pull request #3204 from daltonmaag/fix-unicodedata-typing
Fix typing of script_horizontal_direction()
This commit is contained in:
commit
56731a9f14
@ -1,7 +1,11 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from fontTools.misc.textTools import byteord, tostr
|
from fontTools.misc.textTools import byteord, tostr
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from bisect import bisect_right
|
from bisect import bisect_right
|
||||||
|
from typing import Literal, TypeVar, overload
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# use unicodedata backport compatible with python2:
|
# use unicodedata backport compatible with python2:
|
||||||
@ -15,8 +19,6 @@ from . import Blocks, Scripts, ScriptExtensions, OTTags
|
|||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
tostr(s)
|
|
||||||
for s in (
|
|
||||||
# names from built-in unicodedata module
|
# names from built-in unicodedata module
|
||||||
"lookup",
|
"lookup",
|
||||||
"name",
|
"name",
|
||||||
@ -41,7 +43,6 @@ __all__ = [
|
|||||||
"script_horizontal_direction",
|
"script_horizontal_direction",
|
||||||
"ot_tags_from_script",
|
"ot_tags_from_script",
|
||||||
"ot_tag_to_script",
|
"ot_tag_to_script",
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -195,7 +196,25 @@ RTL_SCRIPTS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def script_horizontal_direction(script_code, default=KeyError):
|
HorizDirection = Literal["RTL", "LTR"]
|
||||||
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def script_horizontal_direction(script_code: str, default: T) -> HorizDirection | T:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def script_horizontal_direction(
|
||||||
|
script_code: str, default: type[KeyError] = KeyError
|
||||||
|
) -> HorizDirection:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def script_horizontal_direction(
|
||||||
|
script_code: str, default: T | type[KeyError] = KeyError
|
||||||
|
) -> HorizDirection | T:
|
||||||
"""Return "RTL" for scripts that contain right-to-left characters
|
"""Return "RTL" for scripts that contain right-to-left characters
|
||||||
according to the Bidi_Class property. Otherwise return "LTR".
|
according to the Bidi_Class property. Otherwise return "LTR".
|
||||||
"""
|
"""
|
||||||
@ -203,7 +222,7 @@ def script_horizontal_direction(script_code, default=KeyError):
|
|||||||
if isinstance(default, type) and issubclass(default, KeyError):
|
if isinstance(default, type) and issubclass(default, KeyError):
|
||||||
raise default(script_code)
|
raise default(script_code)
|
||||||
return default
|
return default
|
||||||
return str("RTL") if script_code in RTL_SCRIPTS else str("LTR")
|
return "RTL" if script_code in RTL_SCRIPTS else "LTR"
|
||||||
|
|
||||||
|
|
||||||
def block(char):
|
def block(char):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user