2020from semantic_version import Version
2121from requests .exceptions import RequestException
2222from bson .objectid import ObjectId
23- from typing import Union , Type , Optional
23+ from typing import Type
2424from tqdm .auto import tqdm
2525from hashlib import md5
2626from pathlib import Path
@@ -478,7 +478,7 @@ def unpack(self) -> str:
478478
479479 return unpacked
480480
481- def write (self , outdir : Optional [ Union [ str , Path ]] = None ) -> Path :
481+ def write (self , outdir : str | Path | None = None ) -> Path :
482482 """Write attachment to file using its name
483483
484484 Args:
@@ -490,7 +490,7 @@ def write(self, outdir: Optional[Union[str, Path]] = None) -> Path:
490490 path .write_bytes (content )
491491 return path
492492
493- def display (self , outdir : Optional [ Union [ str , Path ]] = None ):
493+ def display (self , outdir : str | Path | None = None ):
494494 """Display Image/FileLink for attachment if in IPython/Jupyter
495495
496496 Args:
@@ -519,7 +519,7 @@ def name(self) -> str:
519519 return self ["name" ]
520520
521521 @classmethod
522- def from_data (cls , data : Union [ list , dict ] , name : str = "attachment" ):
522+ def from_data (cls , data : list | dict , name : str = "attachment" ):
523523 """Construct attachment from data dict or list
524524
525525 Args:
@@ -539,7 +539,7 @@ def from_data(cls, data: Union[list, dict], name: str = "attachment"):
539539 )
540540
541541 @classmethod
542- def from_file (cls , path : Union [ Path , str ] ):
542+ def from_file (cls , path : str | Path ):
543543 """Construct attachment from file
544544
545545 Args:
@@ -616,7 +616,7 @@ def from_list(cls, elements: list):
616616 return attachments
617617
618618 @classmethod
619- def from_data (cls , data : Union [ list , dict ] , prefix : str = "attachment" ):
619+ def from_data (cls , data : list | dict , prefix : str = "attachment" ):
620620 """Construct list of attachments from data dict or list
621621
622622 Args:
@@ -870,11 +870,11 @@ class Client(SwaggerClient):
870870
871871 def __init__ (
872872 self ,
873- apikey : Optional [ str ] = None ,
874- headers : Optional [ dict ] = None ,
875- host : Optional [ str ] = None ,
876- project : Optional [ str ] = None ,
877- session : Optional [ requests .Session ] = None ,
873+ apikey : str | None = None ,
874+ headers : dict | None = None ,
875+ host : str | None = None ,
876+ project : str | None = None ,
877+ session : requests .Session | None = None ,
878878 ):
879879 """Initialize the client - only reloads API spec from server as needed
880880
@@ -1056,7 +1056,7 @@ def _get_future(
10561056 params : dict ,
10571057 rel_url : str = "contributions" ,
10581058 op : str = "query" ,
1059- data : Optional [ dict ] = None ,
1059+ data : dict | None = None ,
10601060 ):
10611061 rname = rel_url .split ("/" , 1 )[0 ]
10621062 resource = self .swagger_spec .resources [rname ]
@@ -1075,7 +1075,7 @@ def _get_future(
10751075
10761076 def available_query_params (
10771077 self ,
1078- startswith : Optional [ tuple ] = None ,
1078+ startswith : tuple | None = None ,
10791079 resource : str = "contributions" ,
10801080 ) -> list :
10811081 resources = self .swagger_spec .resources
@@ -1093,7 +1093,7 @@ def available_query_params(
10931093 return [param for param in params if param .startswith (startswith )]
10941094
10951095 def get_project (
1096- self , name : Optional [ str ] = None , fields : Optional [ list ] = None
1096+ self , name : str | None = None , fields : list | None = None
10971097 ) -> Dict :
10981098 """Retrieve a project entry
10991099
@@ -1112,10 +1112,10 @@ def get_project(
11121112
11131113 def query_projects (
11141114 self ,
1115- query : Optional [ dict ] = None ,
1116- term : Optional [ str ] = None ,
1117- fields : Optional [ list ] = None ,
1118- sort : Optional [ str ] = None ,
1115+ query : dict | None = None ,
1116+ term : str | None = None ,
1117+ fields : list | None = None ,
1118+ sort : str | None = None ,
11191119 timeout : int = - 1 ,
11201120 ) -> list [dict ]:
11211121 """Query projects by query and/or term (Atlas Search)
@@ -1219,7 +1219,7 @@ def create_project(
12191219 else :
12201220 raise MPContribsClientError (resp )
12211221
1222- def update_project (self , update : dict , name : Optional [ str ] = None ):
1222+ def update_project (self , update : dict , name : str | None = None ):
12231223 """Update project info
12241224
12251225 Args:
@@ -1285,7 +1285,7 @@ def update_project(self, update: dict, name: Optional[str] = None):
12851285 else :
12861286 raise MPContribsClientError (error )
12871287
1288- def delete_project (self , name : Optional [ str ] = None ):
1288+ def delete_project (self , name : str | None = None ):
12891289 """Delete a project
12901290
12911291 Args:
@@ -1304,7 +1304,7 @@ def delete_project(self, name: Optional[str] = None):
13041304 if resp and "error" in resp :
13051305 raise MPContribsClientError (resp ["error" ])
13061306
1307- def get_contribution (self , cid : str , fields : Optional [ list ] = None ) -> Dict :
1307+ def get_contribution (self , cid : str , fields : list | None = None ) -> Dict :
13081308 """Retrieve a contribution
13091309
13101310 Args:
@@ -1417,7 +1417,7 @@ def get_attachment(self, aid_or_md5: str) -> Attachment:
14171417 )
14181418
14191419 def init_columns (
1420- self , columns : Optional [ dict ] = None , name : Optional [ str ] = None
1420+ self , columns : dict | None = None , name : str | None = None
14211421 ) -> dict :
14221422 """initialize columns for a project to set their order and desired units
14231423
@@ -1575,7 +1575,7 @@ def init_columns(
15751575
15761576 return self .projects .updateProjectByName (pk = name , project = payload ).result ()
15771577
1578- def delete_contributions (self , query : Optional [ dict ] = None , timeout : int = - 1 ):
1578+ def delete_contributions (self , query : dict | None = None , timeout : int = - 1 ):
15791579 """Remove all contributions for a query
15801580
15811581 Args:
@@ -1621,7 +1621,7 @@ def delete_contributions(self, query: Optional[dict] = None, timeout: int = -1):
16211621
16221622 def get_totals (
16231623 self ,
1624- query : Optional [ dict ] = None ,
1624+ query : dict | None = None ,
16251625 timeout : int = - 1 ,
16261626 resource : str = "contributions" ,
16271627 op : str = "query" ,
@@ -1662,11 +1662,11 @@ def get_totals(
16621662
16631663 return result ["total_count" ], result ["total_pages" ]
16641664
1665- def count (self , query : Optional [ dict ] = None ) -> int :
1665+ def count (self , query : dict | None = None ) -> int :
16661666 """shortcut for get_totals()"""
16671667 return self .get_totals (query = query )[0 ]
16681668
1669- def get_unique_identifiers_flags (self , query : Optional [ dict ] = None ) -> dict :
1669+ def get_unique_identifiers_flags (self , query : dict | None = None ) -> dict :
16701670 """Retrieve values for `unique_identifiers` flags.
16711671
16721672 See `client.available_query_params(resource="projects")` for available query parameters.
@@ -1686,10 +1686,10 @@ def get_unique_identifiers_flags(self, query: Optional[dict] = None) -> dict:
16861686
16871687 def get_all_ids (
16881688 self ,
1689- query : Optional [ dict ] = None ,
1690- include : Optional [ list [str ]] = None ,
1689+ query : dict | None = None ,
1690+ include : list [str ] | None = None ,
16911691 timeout : int = - 1 ,
1692- data_id_fields : Optional [ dict ] = None ,
1692+ data_id_fields : dict | None = None ,
16931693 fmt : str = "sets" ,
16941694 op : str = "query" ,
16951695 ) -> dict :
@@ -1844,9 +1844,9 @@ def get_all_ids(
18441844
18451845 def query_contributions (
18461846 self ,
1847- query : Optional [ dict ] = None ,
1848- fields : Optional [ list ] = None ,
1849- sort : Optional [ str ] = None ,
1847+ query : dict | None = None ,
1848+ fields : list | None = None ,
1849+ sort : str | None = None ,
18501850 paginate : bool = False ,
18511851 timeout : int = - 1 ,
18521852 ) -> dict :
@@ -1900,7 +1900,7 @@ def query_contributions(
19001900 return ret
19011901
19021902 def update_contributions (
1903- self , data : dict , query : Optional [ dict ] = None , timeout : int = - 1
1903+ self , data : dict , query : dict | None = None , timeout : int = - 1
19041904 ) -> dict :
19051905 """Apply the same update to all contributions in a project (matching query)
19061906
@@ -1973,7 +1973,7 @@ def update_contributions(
19731973 return {"updated" : updated , "total" : total , "seconds_elapsed" : toc - tic }
19741974
19751975 def make_public (
1976- self , query : Optional [ dict ] = None , recursive : bool = False , timeout : int = - 1
1976+ self , query : dict | None = None , recursive : bool = False , timeout : int = - 1
19771977 ) -> dict :
19781978 """Publish a project and optionally its contributions
19791979
@@ -1986,7 +1986,7 @@ def make_public(
19861986 )
19871987
19881988 def make_private (
1989- self , query : Optional [ dict ] = None , recursive : bool = False , timeout : int = - 1
1989+ self , query : dict | None = None , recursive : bool = False , timeout : int = - 1
19901990 ) -> dict :
19911991 """Make a project and optionally its contributions private
19921992
@@ -2001,7 +2001,7 @@ def make_private(
20012001 def _set_is_public (
20022002 self ,
20032003 is_public : bool ,
2004- query : Optional [ dict ] = None ,
2004+ query : dict | None = None ,
20052005 recursive : bool = False ,
20062006 timeout : int = - 1 ,
20072007 ) -> dict :
@@ -2434,10 +2434,10 @@ def put_future(pk, payload):
24342434
24352435 def download_contributions (
24362436 self ,
2437- query : Optional [ dict ] = None ,
2438- outdir : Union [ str , Path ] = DEFAULT_DOWNLOAD_DIR ,
2437+ query : dict | None = None ,
2438+ outdir : str | Path = DEFAULT_DOWNLOAD_DIR ,
24392439 overwrite : bool = False ,
2440- include : Optional [ list [str ]] = None ,
2440+ include : list [str ] | None = None ,
24412441 timeout : int = - 1 ,
24422442 ) -> list :
24432443 """Download a list of contributions as .json.gz file(s)
@@ -2536,7 +2536,7 @@ def download_contributions(
25362536 def download_structures (
25372537 self ,
25382538 ids : list [str ],
2539- outdir : Union [ str , Path ] = DEFAULT_DOWNLOAD_DIR ,
2539+ outdir : str | Path = DEFAULT_DOWNLOAD_DIR ,
25402540 overwrite : bool = False ,
25412541 timeout : int = - 1 ,
25422542 fmt : str = "json" ,
@@ -2565,7 +2565,7 @@ def download_structures(
25652565 def download_tables (
25662566 self ,
25672567 ids : list [str ],
2568- outdir : Union [ str , Path ] = DEFAULT_DOWNLOAD_DIR ,
2568+ outdir : str | Path = DEFAULT_DOWNLOAD_DIR ,
25692569 overwrite : bool = False ,
25702570 timeout : int = - 1 ,
25712571 fmt : str = "json" ,
@@ -2594,7 +2594,7 @@ def download_tables(
25942594 def download_attachments (
25952595 self ,
25962596 ids : list [str ],
2597- outdir : Union [ str , Path ] = DEFAULT_DOWNLOAD_DIR ,
2597+ outdir : str | Path = DEFAULT_DOWNLOAD_DIR ,
25982598 overwrite : bool = False ,
25992599 timeout : int = - 1 ,
26002600 fmt : str = "json" ,
@@ -2624,7 +2624,7 @@ def _download_resource(
26242624 self ,
26252625 resource : str ,
26262626 ids : list [str ],
2627- outdir : Union [ str , Path ] = DEFAULT_DOWNLOAD_DIR ,
2627+ outdir : str | Path = DEFAULT_DOWNLOAD_DIR ,
26282628 overwrite : bool = False ,
26292629 timeout : int = - 1 ,
26302630 fmt : str = "json" ,
0 commit comments