mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
remove typing_extensions requirement
The typing_extensions package is only necessary now when running mypy. It won't be used at runtime anymore.
This commit is contained in:
@@ -45,7 +45,6 @@ For running Nominatim:
|
|||||||
* [PostgreSQL](https://www.postgresql.org) (9.6+ will work, 11+ strongly recommended)
|
* [PostgreSQL](https://www.postgresql.org) (9.6+ will work, 11+ strongly recommended)
|
||||||
* [PostGIS](https://postgis.net) (2.2+ will work, 3.0+ strongly recommended)
|
* [PostGIS](https://postgis.net) (2.2+ will work, 3.0+ strongly recommended)
|
||||||
* [Python 3](https://www.python.org/) (3.6+)
|
* [Python 3](https://www.python.org/) (3.6+)
|
||||||
* [Python Typing Extensions](https://github.com/python/typing_extensions)
|
|
||||||
* [Psycopg2](https://www.psycopg.org) (2.7+)
|
* [Psycopg2](https://www.psycopg.org) (2.7+)
|
||||||
* [Python Dotenv](https://github.com/theskumar/python-dotenv)
|
* [Python Dotenv](https://github.com/theskumar/python-dotenv)
|
||||||
* [psutil](https://github.com/giampaolo/psutil)
|
* [psutil](https://github.com/giampaolo/psutil)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ It has the following additional requirements:
|
|||||||
* [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
|
* [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
|
||||||
* [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
|
* [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
|
||||||
* [mypy](http://mypy-lang.org/) (plus typing information for external libs)
|
* [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)
|
* [pytest](https://pytest.org)
|
||||||
|
|
||||||
The documentation is built with mkdocs:
|
The documentation is built with mkdocs:
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing_extensions import Protocol
|
|
||||||
|
|
||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
from nominatim.config import Configuration
|
from nominatim.config import Configuration
|
||||||
|
from nominatim.typing import Protocol
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,10 @@ import datetime as dt
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from typing_extensions import TypedDict
|
|
||||||
|
|
||||||
from nominatim.db.connection import Connection
|
from nominatim.db.connection import Connection
|
||||||
from nominatim.tools.exec_utils import get_url
|
from nominatim.tools.exec_utils import get_url
|
||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
|
from nominatim.typing import TypedDict
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
|
ISODATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
|
||||||
|
|||||||
@@ -11,14 +11,13 @@ tasks.
|
|||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from typing_extensions import Protocol
|
|
||||||
from psycopg2 import sql as pysql
|
from psycopg2 import sql as pysql
|
||||||
import psycopg2.extras
|
import psycopg2.extras
|
||||||
|
|
||||||
from nominatim.data.place_info import PlaceInfo
|
from nominatim.data.place_info import PlaceInfo
|
||||||
from nominatim.tokenizer.base import AbstractAnalyzer
|
from nominatim.tokenizer.base import AbstractAnalyzer
|
||||||
from nominatim.db.async_connection import DBConnection
|
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
|
# pylint: disable=C0111
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ from abc import ABC, abstractmethod
|
|||||||
from typing import List, Tuple, Dict, Any, Optional, Iterable
|
from typing import List, Tuple, Dict, Any, Optional, Iterable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing_extensions import Protocol
|
|
||||||
|
|
||||||
from nominatim.config import Configuration
|
from nominatim.config import Configuration
|
||||||
from nominatim.data.place_info import PlaceInfo
|
from nominatim.data.place_info import PlaceInfo
|
||||||
|
from nominatim.typing import Protocol
|
||||||
|
|
||||||
class AbstractAnalyzer(ABC):
|
class AbstractAnalyzer(ABC):
|
||||||
""" The analyzer provides the functions for analysing names and building
|
""" The analyzer provides the functions for analysing names and building
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"""
|
"""
|
||||||
Helper class to create ICU rules from a configuration file.
|
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 importlib
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
@@ -19,7 +19,7 @@ from nominatim.db.connection import Connection
|
|||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
|
from nominatim.tokenizer.place_sanitizer import PlaceSanitizer
|
||||||
from nominatim.tokenizer.icu_token_analysis import ICUTokenAnalysis
|
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
|
import nominatim.data.country_info
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
@@ -130,7 +130,7 @@ class ICURuleLoader:
|
|||||||
def _setup_analysis(self) -> None:
|
def _setup_analysis(self) -> None:
|
||||||
""" Process the rules used for creating the various token analyzers.
|
""" 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):
|
if not isinstance(self.analysis_rules, list):
|
||||||
raise UsageError("Configuration section 'token-analysis' must be a list.")
|
raise UsageError("Configuration section 'token-analysis' must be a list.")
|
||||||
@@ -163,7 +163,7 @@ class ICURuleLoader:
|
|||||||
return ';'.join(flatten_config_list(content, section)) + ';'
|
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
|
""" Factory for a single analysis module. The class saves the configuration
|
||||||
and creates a new token analyzer on request.
|
and creates a new token analyzer on request.
|
||||||
"""
|
"""
|
||||||
@@ -172,7 +172,7 @@ class TokenAnalyzerRule(Generic[T_config]):
|
|||||||
# Find the analysis module
|
# Find the analysis module
|
||||||
module_name = 'nominatim.tokenizer.token_analysis.' \
|
module_name = 'nominatim.tokenizer.token_analysis.' \
|
||||||
+ _get_section(rules, 'analyzer').replace('-', '_')
|
+ _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.
|
# Load the configuration.
|
||||||
self.config = self._analysis_mod.configure(rules, normalization_rules)
|
self.config = self._analysis_mod.configure(rules, normalization_rules)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class ICUTokenAnalysis:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, norm_rules: str, trans_rules: str,
|
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",
|
self.normalizer = Transliterator.createFromRules("icu_normalization",
|
||||||
norm_rules)
|
norm_rules)
|
||||||
trans_rules += ";[:Space:]+ > ' '"
|
trans_rules += ";[:Space:]+ > ' '"
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ Common data types and protocols for sanitizers.
|
|||||||
"""
|
"""
|
||||||
from typing import Optional, Dict, List, Mapping, Callable
|
from typing import Optional, Dict, List, Mapping, Callable
|
||||||
|
|
||||||
from typing_extensions import Protocol, Final
|
|
||||||
from nominatim.tokenizer.sanitizers.config import SanitizerConfig
|
from nominatim.tokenizer.sanitizers.config import SanitizerConfig
|
||||||
from nominatim.data.place_info import PlaceInfo
|
from nominatim.data.place_info import PlaceInfo
|
||||||
|
from nominatim.typing import Protocol, Final
|
||||||
|
|
||||||
class PlaceName:
|
class PlaceName:
|
||||||
""" A searchable name for a place together with properties.
|
""" A searchable name for a place together with properties.
|
||||||
|
|||||||
@@ -7,12 +7,9 @@
|
|||||||
"""
|
"""
|
||||||
Common data types and protocols for analysers.
|
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
|
from nominatim.typing import Protocol
|
||||||
|
|
||||||
|
|
||||||
T_config = TypeVar('T_config') # pylint: disable=invalid-name
|
|
||||||
|
|
||||||
class Analyser(Protocol):
|
class Analyser(Protocol):
|
||||||
""" Instance of the token analyser.
|
""" Instance of the token analyser.
|
||||||
@@ -28,17 +25,17 @@ class Analyser(Protocol):
|
|||||||
and transliterate the result.
|
and transliterate the result.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class AnalysisModule(Protocol[T_config]):
|
class AnalysisModule(Protocol):
|
||||||
""" Protocol for analysis modules.
|
""" 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.
|
""" Prepare the configuration of the analysis module.
|
||||||
This function should prepare all data that can be shared
|
This function should prepare all data that can be shared
|
||||||
between instances of this analyser.
|
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.
|
""" Create a new instance of the analyser.
|
||||||
A separate instance of the analyser is created for each thread
|
A separate instance of the analyser is created for each thread
|
||||||
when used in multi-threading context.
|
when used in multi-threading context.
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ from typing import Iterable, Tuple, Mapping, Sequence, Optional, Set
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from typing_extensions import Protocol
|
|
||||||
|
|
||||||
from psycopg2.sql import Identifier, SQL
|
from psycopg2.sql import Identifier, SQL
|
||||||
|
|
||||||
from nominatim.config import Configuration
|
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.importer_statistics import SpecialPhrasesImporterStatistics
|
||||||
from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
|
from nominatim.tools.special_phrases.special_phrase import SpecialPhrase
|
||||||
from nominatim.tokenizer.base import AbstractTokenizer
|
from nominatim.tokenizer.base import AbstractTokenizer
|
||||||
|
from nominatim.typing import Protocol
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
from typing import Any, Union, Mapping, TypeVar, Sequence, TYPE_CHECKING
|
||||||
|
|
||||||
# Generics varaible names do not confirm to naming styles, ignore globally here.
|
# 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:
|
if TYPE_CHECKING:
|
||||||
import psycopg2.sql
|
import psycopg2.sql
|
||||||
@@ -36,3 +37,16 @@ class DictCursorResult(Mapping[str, Any]):
|
|||||||
DictCursorResults = Sequence[DictCursorResult]
|
DictCursorResults = Sequence[DictCursorResult]
|
||||||
|
|
||||||
T_cursor = TypeVar('T_cursor', bound='psycopg2.extensions.cursor')
|
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
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
|
|||||||
# Some of the Python packages that come with Ubuntu 18.04 are too old, so
|
# Some of the Python packages that come with Ubuntu 18.04 are too old, so
|
||||||
# install the latest version from pip:
|
# 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
|
# System Configuration
|
||||||
|
|||||||
@@ -30,11 +30,6 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
|
|||||||
python3-psycopg2 python3-psutil python3-jinja2 \
|
python3-psycopg2 python3-psutil python3-jinja2 \
|
||||||
python3-icu python3-datrie python3-yaml python3-pip git
|
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
|
# System Configuration
|
||||||
# ====================
|
# ====================
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export DEBIAN_FRONTEND=noninteractive #DOCS:
|
|||||||
postgresql-contrib-14 postgresql-14-postgis-3-scripts \
|
postgresql-contrib-14 postgresql-14-postgis-3-scripts \
|
||||||
php php-pgsql php-intl libicu-dev python3-dotenv \
|
php php-pgsql php-intl libicu-dev python3-dotenv \
|
||||||
python3-psycopg2 python3-psutil python3-jinja2 \
|
python3-psycopg2 python3-psutil python3-jinja2 \
|
||||||
python3-typing-extensions \
|
|
||||||
python3-icu python3-datrie git
|
python3-icu python3-datrie git
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user