summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Morton <seth.m.morton@gmail.com>2021-10-24 13:06:49 -0700
committerSeth Morton <seth.m.morton@gmail.com>2021-10-24 13:06:49 -0700
commit6d4d95c03eda201279ac7919fd3a92d51cde8a09 (patch)
tree1a26157b0b915b7de6cf67fedcee579219f65ab5
parentf87d6b5b74e331699a89f4675e4b95ba26587186 (diff)
downloadnatsort-6d4d95c03eda201279ac7919fd3a92d51cde8a09.tar.gz
Satisfy mypy for library as-is
Without adding any annotations, make sure mypy is happy.
-rw-r--r--natsort/compat/fake_fastnumbers.py6
-rw-r--r--natsort/compat/locale.py8
-rw-r--r--natsort/natsort.py2
-rw-r--r--setup.cfg8
4 files changed, 18 insertions, 6 deletions
diff --git a/natsort/compat/fake_fastnumbers.py b/natsort/compat/fake_fastnumbers.py
index 7177551..570083f 100644
--- a/natsort/compat/fake_fastnumbers.py
+++ b/natsort/compat/fake_fastnumbers.py
@@ -10,7 +10,7 @@ import unicodedata
# Local imports.
from natsort.unicode_numbers import decimal_chars
-NAN_INF = [
+_NAN_INF = [
"INF",
"INf",
"Inf",
@@ -28,8 +28,8 @@ NAN_INF = [
"nAN",
"Nan",
]
-NAN_INF.extend(["+" + x[:2] for x in NAN_INF] + ["-" + x[:2] for x in NAN_INF])
-NAN_INF = frozenset(NAN_INF)
+_NAN_INF.extend(["+" + x[:2] for x in _NAN_INF] + ["-" + x[:2] for x in _NAN_INF])
+NAN_INF = frozenset(_NAN_INF)
ASCII_NUMS = "0123456789+-"
POTENTIAL_FIRST_CHAR = frozenset(decimal_chars + list(ASCII_NUMS + "."))
diff --git a/natsort/compat/locale.py b/natsort/compat/locale.py
index ccb5592..1edb67f 100644
--- a/natsort/compat/locale.py
+++ b/natsort/compat/locale.py
@@ -3,9 +3,8 @@
Interface for natsort to access locale functionality without
having to worry about if it is using PyICU or the built-in locale.
"""
-
-# Std. lib imports.
import sys
+import typing as t
# This string should be sorted after any other byte string because
# it contains the max unicode character repeated 20 times.
@@ -13,6 +12,11 @@ import sys
null_string = ""
null_string_max = chr(sys.maxunicode) * 20
+# This variable could be str or bytes depending on the locale library
+# being used, so give the type-checker this information.
+null_string_locale: t.Union[str, bytes]
+null_string_locale_max: t.Union[str, bytes]
+
# strxfrm can be buggy (especially on BSD-based systems),
# so prefer icu if available.
try: # noqa: C901
diff --git a/natsort/natsort.py b/natsort/natsort.py
index 0430a44..1402cf8 100644
--- a/natsort/natsort.py
+++ b/natsort/natsort.py
@@ -622,7 +622,7 @@ def _split_apply(v, key=None):
# Choose the implementation based on the host OS
if platform.system() == "Windows":
- from ctypes import wintypes, windll
+ from ctypes import wintypes, windll # type: ignore
from functools import cmp_to_key
_windows_sort_cmp = windll.Shlwapi.StrCmpLogicalW
diff --git a/setup.cfg b/setup.cfg
index a045246..93c0f1c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -63,3 +63,11 @@ exclude =
dist,
docs,
.venv
+
+[mypy]
+
+[mypy-icu]
+ignore_missing_imports = True
+
+[mypy-fastnumbers]
+ignore_missing_imports = True