70
70
from .options import OPTIONS , _get_keep_attrs
71
71
from .pycompat import dask_array_type
72
72
from .utils import (
73
+ Default ,
73
74
Frozen ,
74
75
SortedKeysDict ,
76
+ _default ,
75
77
_check_inplace ,
76
78
decode_numpy_dict_values ,
77
79
either_dict_or_kwargs ,
@@ -856,23 +858,18 @@ def _construct_direct(
856
858
obj ._accessors = None
857
859
return obj
858
860
859
- __default = object ()
860
-
861
861
@classmethod
862
862
def _from_vars_and_coord_names (cls , variables , coord_names , attrs = None ):
863
863
return cls ._construct_direct (variables , coord_names , attrs = attrs )
864
864
865
- # TODO(shoyer): renable type checking on this signature when pytype has a
866
- # good way to handle defaulting arguments to a sentinel value:
867
- # https://github.com/python/mypy/issues/1803
868
- def _replace ( # type: ignore
865
+ def _replace (
869
866
self ,
870
867
variables : Dict [Hashable , Variable ] = None ,
871
868
coord_names : Set [Hashable ] = None ,
872
869
dims : Dict [Any , int ] = None ,
873
- attrs : Optional [Dict [Hashable , Any ]] = __default ,
874
- indexes : Optional [Dict [Any , pd .Index ]] = __default ,
875
- encoding : Optional [dict ] = __default ,
870
+ attrs : Union [Dict [Hashable , Any ], None , Default ] = _default ,
871
+ indexes : Union [Dict [Any , pd .Index ], None , Default ] = _default ,
872
+ encoding : Union [dict , None , Default ] = _default ,
876
873
inplace : bool = False ,
877
874
) -> "Dataset" :
878
875
"""Fastpath constructor for internal use.
@@ -890,12 +887,12 @@ def _replace( # type: ignore
890
887
self ._coord_names = coord_names
891
888
if dims is not None :
892
889
self ._dims = dims
893
- if attrs is not self . __default :
894
- self ._attrs = attrs
895
- if indexes is not self . __default :
896
- self ._indexes = indexes
897
- if encoding is not self . __default :
898
- self ._encoding = encoding
890
+ if attrs is not _default :
891
+ self ._attrs = attrs # type: ignore # FIXME need mypy 0.750
892
+ if indexes is not _default :
893
+ self ._indexes = indexes # type: ignore # FIXME need mypy 0.750
894
+ if encoding is not _default :
895
+ self ._encoding = encoding # type: ignore # FIXME need mypy 0.750
899
896
obj = self
900
897
else :
901
898
if variables is None :
@@ -904,23 +901,23 @@ def _replace( # type: ignore
904
901
coord_names = self ._coord_names .copy ()
905
902
if dims is None :
906
903
dims = self ._dims .copy ()
907
- if attrs is self . __default :
904
+ if attrs is _default :
908
905
attrs = copy .copy (self ._attrs )
909
- if indexes is self . __default :
906
+ if indexes is _default :
910
907
indexes = copy .copy (self ._indexes )
911
- if encoding is self . __default :
908
+ if encoding is _default :
912
909
encoding = copy .copy (self ._encoding )
913
910
obj = self ._construct_direct (
914
911
variables , coord_names , dims , attrs , indexes , encoding
915
912
)
916
913
return obj
917
914
918
- def _replace_with_new_dims ( # type: ignore
915
+ def _replace_with_new_dims (
919
916
self ,
920
917
variables : Dict [Hashable , Variable ],
921
918
coord_names : set = None ,
922
- attrs : Optional [Dict [Hashable , Any ]] = __default ,
923
- indexes : Dict [Hashable , pd .Index ] = __default ,
919
+ attrs : Union [Dict [Hashable , Any ], None , Default ] = _default ,
920
+ indexes : Union [ Dict [Hashable , pd .Index ], None , Default ] = _default ,
924
921
inplace : bool = False ,
925
922
) -> "Dataset" :
926
923
"""Replace variables with recalculated dimensions."""
@@ -929,12 +926,12 @@ def _replace_with_new_dims( # type: ignore
929
926
variables , coord_names , dims , attrs , indexes , inplace = inplace
930
927
)
931
928
932
- def _replace_vars_and_dims ( # type: ignore
929
+ def _replace_vars_and_dims (
933
930
self ,
934
931
variables : Dict [Hashable , Variable ],
935
932
coord_names : set = None ,
936
933
dims : Dict [Hashable , int ] = None ,
937
- attrs : Dict [Hashable , Any ] = __default ,
934
+ attrs : Union [ Dict [Hashable , Any ], None , Default ] = _default ,
938
935
inplace : bool = False ,
939
936
) -> "Dataset" :
940
937
"""Deprecated version of _replace_with_new_dims().
0 commit comments