44import logging
55import re
66from abc import ABCMeta , abstractmethod
7+ from collections .abc import Iterable , Mapping , MutableMapping , MutableSequence , Sequence
78from operator import itemgetter
89from pathlib import Path
910from typing import (
1011 Any ,
11- Iterable ,
12- Mapping ,
13- MutableMapping ,
14- MutableSequence ,
15- Optional ,
16- Sequence ,
17- Set ,
18- Tuple ,
19- Union ,
2012)
2113from urllib .parse import unquote
2214
@@ -55,11 +47,11 @@ def metabase(self) -> Metabase:
5547 def extract_exposures (
5648 self ,
5749 output_path : str = DEFAULT_EXPOSURES_OUTPUT_PATH ,
58- output_grouping : Optional [ str ] = None ,
59- collection_filter : Optional [ Filter ] = None ,
50+ output_grouping : str | None = None ,
51+ collection_filter : Filter | None = None ,
6052 allow_personal_collections : bool = False ,
6153 exclude_unverified : bool = False ,
62- tags : Optional [ Sequence [str ]] = None ,
54+ tags : Sequence [str ] | None = None ,
6355 ) -> Iterable [Mapping ]:
6456 """Extract dbt exposures from Metabase.
6557
@@ -273,7 +265,7 @@ def __exposure_query(self, ctx: _Context, exposure: _Exposure, card: Mapping):
273265 dataset_query = card .get ("dataset_query" , {})
274266 query = dataset_query .get ("query" , {})
275267
276- query_source : Union [ str , int ] = query .get ("source-table" , card .get ("table_id" ))
268+ query_source : str | int = query .get ("source-table" , card .get ("table_id" ))
277269 if isinstance (query_source , str ) and query_source .startswith ("card__" ):
278270 # Question based on another question
279271 source_card_uid = query_source .split ("__" )[- 1 ]
@@ -288,7 +280,7 @@ def __exposure_query(self, ctx: _Context, exposure: _Exposure, card: Mapping):
288280
289281 # Find models in joins
290282 for join in query .get ("joins" , []):
291- join_source : Union [ str , int ] = join .get ("source-table" )
283+ join_source : str | int = join .get ("source-table" )
292284 if isinstance (join_source , str ) and join_source .startswith ("card__" ):
293285 # Question based on another question
294286 source_card_uid = join_source .split ("__" )[- 1 ]
@@ -338,8 +330,8 @@ def __exposure_mbql5_stage_mbql(
338330 """Extracts exposures from an MBQL 5 GUI stage."""
339331
340332 # Extract source-table or source-card
341- source_table : Optional [ int ] = stage .get ("source-table" )
342- source_card : Optional [ int ] = stage .get ("source-card" )
333+ source_table : int | None = stage .get ("source-table" )
334+ source_card : int | None = stage .get ("source-card" )
343335
344336 if source_card is not None :
345337 # Stage based on another card/question
@@ -437,11 +429,11 @@ def __format_exposure(
437429 created_at : str ,
438430 creator_name : str ,
439431 creator_email : str ,
440- last_used_at : Optional [ str ] ,
441- average_query_time : Optional [ str ] ,
442- native_query : Optional [ str ] ,
432+ last_used_at : str | None ,
433+ average_query_time : str | None ,
434+ native_query : str | None ,
443435 depends_on : Iterable [str ],
444- tags : Optional [ Sequence [str ]] ,
436+ tags : Sequence [str ] | None ,
445437 ) -> Mapping :
446438 """Builds dbt exposure representation (see https://docs.getdbt.com/reference/exposure-properties)."""
447439
@@ -510,13 +502,13 @@ def __write_exposures(
510502 self ,
511503 exposures : Iterable [Mapping ],
512504 output_path : str ,
513- output_grouping : Optional [ str ] ,
505+ output_grouping : str | None ,
514506 ):
515507 """Write exposures to output files."""
516508
517- grouped : MutableMapping [Tuple [str , ...], MutableSequence [Mapping ]] = {}
509+ grouped : MutableMapping [tuple [str , ...], MutableSequence [Mapping ]] = {}
518510 for exposure in exposures :
519- group : Tuple [str , ...] = ("exposures" ,)
511+ group : tuple [str , ...] = ("exposures" ,)
520512 if output_grouping == "collection" :
521513 group = (exposure ["collection" ],)
522514 elif output_grouping == "type" :
@@ -563,7 +555,7 @@ class _Exposure:
563555 header : str = ""
564556 creator_name : str = ""
565557 creator_email : str = ""
566- average_query_time : Optional [ str ] = None
567- last_used_at : Optional [ str ] = None
568- native_query : Optional [ str ] = None
569- depends : Set [str ] = dc .field (default_factory = set )
558+ average_query_time : str | None = None
559+ last_used_at : str | None = None
560+ native_query : str | None = None
561+ depends : set [str ] = dc .field (default_factory = set )
0 commit comments