7070from .options import OPTIONS , _get_keep_attrs
7171from .pycompat import dask_array_type
7272from .utils import (
73+ Default ,
7374 Frozen ,
7475 SortedKeysDict ,
76+ _default ,
7577 _check_inplace ,
7678 decode_numpy_dict_values ,
7779 either_dict_or_kwargs ,
@@ -856,23 +858,18 @@ def _construct_direct(
856858 obj ._accessors = None
857859 return obj
858860
859- __default = object ()
860-
861861 @classmethod
862862 def _from_vars_and_coord_names (cls , variables , coord_names , attrs = None ):
863863 return cls ._construct_direct (variables , coord_names , attrs = attrs )
864864
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 (
869866 self ,
870867 variables : Dict [Hashable , Variable ] = None ,
871868 coord_names : Set [Hashable ] = None ,
872869 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 ,
876873 inplace : bool = False ,
877874 ) -> "Dataset" :
878875 """Fastpath constructor for internal use.
@@ -890,12 +887,12 @@ def _replace( # type: ignore
890887 self ._coord_names = coord_names
891888 if dims is not None :
892889 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
899896 obj = self
900897 else :
901898 if variables is None :
@@ -904,23 +901,23 @@ def _replace( # type: ignore
904901 coord_names = self ._coord_names .copy ()
905902 if dims is None :
906903 dims = self ._dims .copy ()
907- if attrs is self . __default :
904+ if attrs is _default :
908905 attrs = copy .copy (self ._attrs )
909- if indexes is self . __default :
906+ if indexes is _default :
910907 indexes = copy .copy (self ._indexes )
911- if encoding is self . __default :
908+ if encoding is _default :
912909 encoding = copy .copy (self ._encoding )
913910 obj = self ._construct_direct (
914911 variables , coord_names , dims , attrs , indexes , encoding
915912 )
916913 return obj
917914
918- def _replace_with_new_dims ( # type: ignore
915+ def _replace_with_new_dims (
919916 self ,
920917 variables : Dict [Hashable , Variable ],
921918 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 ,
924921 inplace : bool = False ,
925922 ) -> "Dataset" :
926923 """Replace variables with recalculated dimensions."""
@@ -929,12 +926,12 @@ def _replace_with_new_dims( # type: ignore
929926 variables , coord_names , dims , attrs , indexes , inplace = inplace
930927 )
931928
932- def _replace_vars_and_dims ( # type: ignore
929+ def _replace_vars_and_dims (
933930 self ,
934931 variables : Dict [Hashable , Variable ],
935932 coord_names : set = None ,
936933 dims : Dict [Hashable , int ] = None ,
937- attrs : Dict [Hashable , Any ] = __default ,
934+ attrs : Union [ Dict [Hashable , Any ], None , Default ] = _default ,
938935 inplace : bool = False ,
939936 ) -> "Dataset" :
940937 """Deprecated version of _replace_with_new_dims().
0 commit comments