]> git.openstreetmap.org Git - nominatim.git/commitdiff
remove typing_extensions requirement
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 17 Jul 2022 21:18:55 +0000 (23:18 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 18 Jul 2022 07:55:58 +0000 (09:55 +0200)
The typing_extensions package is only necessary now when running mypy.
It won't be used at runtime anymore.

15 files changed:
docs/admin/Installation.md
docs/develop/Development-Environment.md
nominatim/clicmd/args.py
nominatim/db/status.py
nominatim/indexer/runners.py
nominatim/tokenizer/base.py
nominatim/tokenizer/icu_rule_loader.py
nominatim/tokenizer/icu_token_analysis.py
nominatim/tokenizer/sanitizers/base.py
nominatim/tokenizer/token_analysis/base.py
nominatim/tools/special_phrases/sp_importer.py
nominatim/typing.py
vagrant/Install-on-Ubuntu-18.sh
vagrant/Install-on-Ubuntu-20.sh
vagrant/Install-on-Ubuntu-22.sh

index d7d35b7e218bf6259d58704d582675138a099bbc..96546cf3de57dabd1f27b338220767216235f2d7 100644 (file)
@@ -45,7 +45,6 @@ For running Nominatim:
   * [PostgreSQL](https://www.postgresql.org) (9.6+ will work, 11+ strongly recommended)
   * [PostGIS](https://postgis.net) (2.2+ will work, 3.0+ strongly recommended)
   * [Python 3](https://www.python.org/) (3.6+)
-  * [Python Typing Extensions](https://github.com/python/typing_extensions)
   * [Psycopg2](https://www.psycopg.org) (2.7+)
   * [Python Dotenv](https://github.com/theskumar/python-dotenv)
   * [psutil](https://github.com/giampaolo/psutil)
index 05bd50dede36a2d82f053fd393e862f602558f31..65dc79907c8bcdbb697d80803eaeeb5520182c82 100644 (file)
@@ -34,6 +34,7 @@ It has the following additional requirements:
 * [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
 * [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
 * [mypy](http://mypy-lang.org/) (plus typing information for external libs)
+* [Python Typing Extensions](https://github.com/python/typing_extensions) (for Python < 3.9)
 * [pytest](https://pytest.org)
 
 The documentation is built with mkdocs:
index f5f1b98eb26c0a29a3a32712ee7e63a0e2224cad..c976f394849be1496ca97ba320ea319dc8397ecf 100644 (file)
@@ -12,10 +12,9 @@ import argparse
 import logging
 from pathlib import Path
 
-from typing_extensions import Protocol
-
 from nominatim.errors import UsageError
 from nominatim.config import Configuration
+from nominatim.typing import Protocol
 
 LOG = logging.getLogger()
 
index f0039546474244d97e419281d6b9e365cdb5c3c8..aea25a976d8829a0fe65247e9d6fa8acb430c6c7 100644 (file)
@@ -12,11 +12,10 @@ import datetime as dt
 import logging
 import re
 
-from typing_extensions import TypedDict
-
 from nominatim.db.connection import Connection
 from nominatim.tools.exec_utils import get_url
 from nominatim.errors import UsageError
+from nominatim.typing import TypedDict
 
 LOG = logging.getLogger()
 ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
index 973c6ea98c0cf4741a61ebd72c91770530ca056c..bbadd282ec96c538baa7ff3926e75bd5bd6cbe69 100644 (file)
@@ -11,14 +11,13 @@ tasks.
 from typing import Any, List
 import functools
 
-from typing_extensions import Protocol
 from psycopg2 import sql as pysql
 import psycopg2.extras
 
 from nominatim.data.place_info import PlaceInfo
 from nominatim.tokenizer.base import AbstractAnalyzer
 from nominatim.db.async_connection import DBConnection
-from nominatim.typing import Query, DictCursorResult, DictCursorResults
+from nominatim.typing import Query, DictCursorResult, DictCursorResults, Protocol
 
 # pylint: disable=C0111
 
index 1c1ca9f7bcfca3d7fa407504ac0b0c9d728191a1..dbc4cfadcefbe0df9a497afe4d44ec41fb3f913f 100644 (file)
@@ -12,10 +12,9 @@ from abc import ABC, abstractmethod
 from typing import List, Tuple, Dict, Any, Optional, Iterable
 from pathlib import Path
 
-from typing_extensions import Protocol
-
 from nominatim.config import Configuration
 from nominatim.data.place_info import PlaceInfo
+from nominatim.typing import Protocol
 
 class AbstractAnalyzer(ABC):
     """ The analyzer provides the functions for analysing names and building
index 7199f5f5535aab5eb4429e862512e34e15310c29..84040ddc36f86a1ad66722abfbcd4f444fff652a 100644 (file)
@@ -7,7 +7,7 @@
 """
 Helper class to create ICU rules from a configuration file.
 """
-from typing import Mapping, Any, Generic, Dict, Optional
+from typing import Mapping, Any, Dict, Optional
 import importlib
 import io
 import json
@@ -19,7 +19,7 @@ from nominatim.db.connection import Connection
 from nominatim.errors import UsageError
 from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
 from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis
-from nominatim.tokenizer.token_analysis.base import AnalysisModule, Analyser, T_config
+from nominatim.tokenizer.token_analysis.base import AnalysisModule, Analyser
 import nominatim.data.country_info
 
 LOG = logging.getLogger()
@@ -130,7 +130,7 @@ class ICURuleLoader:
     def _setup_analysis(self) -> None:
         """ Process the rules used for creating the various token analyzers.
         """
-        self.analysis: Dict[Optional[str], TokenAnalyzerRule[Any]]  = {}
+        self.analysis: Dict[Optional[str], TokenAnalyzerRule]  = {}
 
         if not isinstance(self.analysis_rules, list):
             raise UsageError("Configuration section 'token-analysis' must be a list.")
@@ -163,7 +163,7 @@ class ICURuleLoader:
         return ';'.join(flatten_config_list(content, section)) + ';'
 
 
-class TokenAnalyzerRule(Generic[T_config]):
+class TokenAnalyzerRule:
     """ Factory for a single analysis module. The class saves the configuration
         and creates a new token analyzer on request.
     """
@@ -172,7 +172,7 @@ class TokenAnalyzerRule(Generic[T_config]):
         # Find the analysis module
         module_name = 'nominatim.tokenizer.token_analysis.' \
                       + _get_section(rules, 'analyzer').replace('-', '_')
-        self._analysis_mod: AnalysisModule[T_config] = importlib.import_module(module_name)
+        self._analysis_mod: AnalysisModule = importlib.import_module(module_name)
 
         # Load the configuration.
         self.config = self._analysis_mod.configure(rules, normalization_rules)
index 62e6a80a28d9df2b0c21c6074a92902263017239..3c4d729885450c5907283f9f7801f2df01296973 100644 (file)
@@ -23,7 +23,7 @@ class ICUTokenAnalysis:
     """
 
     def __init__(self, norm_rules: str, trans_rules: str,
-                 analysis_rules: Mapping[Optional[str], 'TokenAnalyzerRule[Any]']):
+                 analysis_rules: Mapping[Optional[str], 'TokenAnalyzerRule']):
         self.normalizer = Transliterator.createFromRules("icu_normalization",
                                                          norm_rules)
         trans_rules += ";[:Space:]+ > ' '"
index f2e1bc41538fbed863c1d2c768c2cb3eeb520632..692c6d5ffe8450d573bfbb7cfb385feccc0854e3 100644 (file)
@@ -9,9 +9,9 @@ Common data types and protocols for sanitizers.
 """
 from typing import Optional, Dict, List, Mapping, Callable
 
-from typing_extensions import Protocol, Final
 from nominatim.tokenizer.sanitizers.config import SanitizerConfig
 from nominatim.data.place_info import PlaceInfo
+from nominatim.typing import Protocol, Final
 
 class PlaceName:
     """ A searchable name for a place together with properties.
index b55b4f7c2f6837bc7f30fc1ac538143aa483a0f5..b2a4386cb6d2ea640d7fa25053c4b9b74f987686 100644 (file)
@@ -7,12 +7,9 @@
 """
 Common data types and protocols for analysers.
 """
-from typing import TypeVar, Mapping, List, Any
+from typing import Mapping, List, Any
 
-from typing_extensions import Protocol
-
-
-T_config = TypeVar('T_config') # pylint: disable=invalid-name
+from nominatim.typing import Protocol
 
 class Analyser(Protocol):
     """ Instance of the token analyser.
@@ -28,17 +25,17 @@ class Analyser(Protocol):
             and transliterate the result.
         """
 
-class AnalysisModule(Protocol[T_config]):
+class AnalysisModule(Protocol):
     """ Protocol for analysis modules.
     """
 
-    def configure(self, rules: Mapping[str, Any], normalization_rules: str) -> T_config:
+    def configure(self, rules: Mapping[str, Any], normalization_rules: str) -> Any:
         """ Prepare the configuration of the analysis module.
             This function should prepare all data that can be shared
             between instances of this analyser.
         """
 
-    def create(self, normalizer: Any, transliterator: Any, config: T_config) -> Analyser:
+    def create(self, normalizer: Any, transliterator: Any, config: Any) -> Analyser:
         """ Create a new instance of the analyser.
             A separate instance of the analyser is created for each thread
             when used in multi-threading context.
index 6ca6a1e17b8ef7db34f5015ca65ce61d7e7c0f52..8906e03e2c6ce6d1def0276802b5aed30154ad1b 100644 (file)
@@ -17,8 +17,6 @@ from typing import Iterable, Tuple, Mapping, Sequence, Optional, Set
 import logging
 import re
 
-from typing_extensions import Protocol
-
 from psycopg2.sql import Identifier, SQL
 
 from nominatim.config import Configuration
@@ -26,6 +24,7 @@ from nominatim.db.connection import Connection
 from nominatim.tools.special_phrases.importer_statistics import SpecialPhrasesImporterStatistics
 from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
 from nominatim.tokenizer.base import AbstractTokenizer
+from nominatim.typing import Protocol
 
 LOG = logging.getLogger()
 
index 36bde8347e7dd4fc8d94e9b9ea422f5ec1a77810..308f3e6a2cbb515245e81aa47a739ce562b1c04e 100644 (file)
@@ -12,7 +12,8 @@ Complex type definitions are moved here, to keep the source files readable.
 from typing import Any, Union, Mapping, TypeVar, Sequence, TYPE_CHECKING
 
 # Generics varaible names do not confirm to naming styles, ignore globally here.
-# pylint: disable=invalid-name,abstract-method,multiple-statements,missing-class-docstring
+# pylint: disable=invalid-name,abstract-method,multiple-statements
+# pylint: disable=missing-class-docstring,useless-import-alias
 
 if TYPE_CHECKING:
     import psycopg2.sql
@@ -36,3 +37,16 @@ class DictCursorResult(Mapping[str, Any]):
 DictCursorResults = Sequence[DictCursorResult]
 
 T_cursor = TypeVar('T_cursor', bound='psycopg2.extensions.cursor')
+
+# The following typing features require typing_extensions to work
+# on all supported Python versions.
+# Only require this for type checking but not for normal operations.
+
+if TYPE_CHECKING:
+    from typing_extensions import (Protocol as Protocol,
+                                   Final as Final,
+                                   TypedDict as TypedDict)
+else:
+    Protocol = object
+    Final = 'Final'
+    TypedDict = dict
index b853cdb53204a508beb33335e033dff2c9edc75e..3537bcf4486c0050298cb4afe2499a91c318907a 100755 (executable)
@@ -33,7 +33,7 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
 # Some of the Python packages that come with Ubuntu 18.04 are too old, so
 # install the latest version from pip:
 
-    pip3 install --user python-dotenv datrie pyyaml psycopg2-binary typing-extensions
+    pip3 install --user python-dotenv datrie pyyaml psycopg2-binary
 
 #
 # System Configuration
index 365f609fb315a4819c5976a22ba4ac1e615734cb..8dcc2fef0b07ec1f79295fafbb14a01792c29f18 100755 (executable)
@@ -30,11 +30,6 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
                         python3-psycopg2 python3-psutil python3-jinja2 \
                         python3-icu python3-datrie python3-yaml python3-pip git
 
-# Nominatim uses some typing features only available in later Python versions.
-# Install the latest version of the backport package:
-
-    pip3 install --user typing-extensions
-
 #
 # System Configuration
 # ====================
index b86f1f65f76e06dbe18e59586297586b42c73f1c..dbb70ffe6546ab9db484f2d22d9f2145ae044cc0 100755 (executable)
@@ -28,7 +28,6 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
                         postgresql-contrib-14 postgresql-14-postgis-3-scripts \
                         php php-pgsql php-intl libicu-dev python3-dotenv \
                         python3-psycopg2 python3-psutil python3-jinja2 \
-                        python3-typing-extensions \
                         python3-icu python3-datrie git
 
 #