1+ from __future__ import annotations
2+
13import json
24import os
35
46from typing import (
7+ TYPE_CHECKING ,
58 Any ,
6- Dict ,
7- Mapping ,
8- Optional ,
9- Sequence ,
109)
1110
1211from qgis .core import QgsMapLayer , QgsProject
1514from .layer_options import layerOptionDefinitions
1615from .models import MappingQgisGeometryType
1716
17+ if TYPE_CHECKING :
18+ from collections .abc import Mapping , Sequence
19+
1820
1921class LizmapConfigError (Exception ):
2022 pass
@@ -34,9 +36,9 @@ def __init__(self, project: QgsProject):
3436
3537 self ._WFSLayers = self .project .readListEntry ("WFSLayers" , "" )[0 ]
3638
37- self ._layer_attributes : Dict = {}
38- self ._global_options : Dict = {}
39- self ._layer_options : Dict = {}
39+ self ._layer_attributes : dict = {}
40+ self ._global_options : dict = {}
41+ self ._layer_options : dict = {}
4042
4143 @staticmethod
4244 def _load_project (path ):
@@ -48,7 +50,7 @@ def _load_project(path):
4850 raise LizmapConfigError ("Error reading qgis project" )
4951 return project
5052
51- def get_layer_by_name (self , name : str ) -> Optional [ QgsMapLayer ] :
53+ def get_layer_by_name (self , name : str ) -> QgsMapLayer | None :
5254 """Return a unique layer by its name"""
5355 matches = self .project .mapLayersByName (name )
5456 if len (matches ) > 0 :
@@ -57,9 +59,9 @@ def get_layer_by_name(self, name: str) -> Optional[QgsMapLayer]:
5759
5860 def to_json (
5961 self ,
60- p_global_options : Optional [ Mapping [str , Any ]] = None ,
61- p_layer_options : Optional [ Mapping [str , Any ]] = None ,
62- p_attributes_options : Optional [ Mapping [str , Any ]] = None ,
62+ p_global_options : Mapping [str , Any ] | None = None ,
63+ p_layer_options : Mapping [str , Any ] | None = None ,
64+ p_attributes_options : Mapping [str , Any ] | None = None ,
6365 sort_keys : bool = False ,
6466 indent : int = 4 ,
6567 ** kwargs ,
@@ -86,7 +88,7 @@ def to_json(
8688 # Write json to the cfg file
8789 return json .dumps (config , sort_keys = sort_keys , indent = indent , ** kwargs )
8890
89- def set_global_options (self , options : Optional [ Mapping [str , Any ]] = None ):
91+ def set_global_options (self , options : Mapping [str , Any ] | None = None ):
9092 """Set the global lizmap configuration options"""
9193 # set defaults
9294 self ._global_options = {
@@ -171,7 +173,7 @@ def add_layer(self, layer: QgsMapLayer, **options) -> Mapping[str, Any]:
171173 self ._layer_options [lid ] = lo
172174 return lo
173175
174- def set_layer_options (self , p_layer_options : Optional [ Mapping [str , Any ]] = None ):
176+ def set_layer_options (self , p_layer_options : Mapping [str , Any ] | None = None ):
175177 """Set the configuration options for the the project layers
176178
177179 :param p_layer_options: dict of options for each layers
@@ -207,7 +209,7 @@ def publish_layer_attribute_table(
207209
208210 # Check that the layer has WFS enabled
209211 if not self .hasWFSCapabilities (layer ):
210- raise LizmapConfigError ("WFS Required for layer %s" % layer .name ())
212+ raise LizmapConfigError (f "WFS Required for layer { layer .name ()} " )
211213
212214 lyr_name = layer .name ()
213215 lyr_attrs = self ._layer_attributes .get (lyr_name )
@@ -249,10 +251,10 @@ def set_wmsextent(self, xmin: float, ymin: float, xmax: float, ymax: float):
249251 # noinspection PyPep8Naming
250252 def configure_server_options (
251253 self ,
252- WMSTitle : Optional [ str ] = None ,
253- WMSDescription : Optional [ str ] = None ,
254+ WMSTitle : str | None = None ,
255+ WMSDescription : str | None = None ,
254256 WFSLayersPrecision : int = 6 ,
255- WMSExtent : Optional [ Sequence [int ]] = None ,
257+ WMSExtent : Sequence [int ] | None = None ,
256258 ):
257259 """Configure server options for layers in the qgis project
258260
0 commit comments