use inspect.signature to populate kwargs
Filename / URL patterns.
"""
+import inspect
from dataclasses import dataclass, field, replace
from enum import Enum
from itertools import product
@@ -267,10 +268,9 @@ def prune_pattern(fp: FilePattern, nkeep: int = 2) -> FilePattern:
else: # pragma: no cover
assert "Should never happen"
- return FilePattern(
- fp.format_function,
- *new_combine_dims,
- fsspec_open_kwargs=fp.fsspec_open_kwargs,
- query_string_secrets=fp.query_string_secrets,
- is_opendap=fp.is_opendap,
- )
+ sig = inspect.signature(fp.__init__)
+ kwargs = {
+ param: getattr(fp, param) for param in sig.parameters.keys()
+ if param not in ['format_function', 'combine_dims']
+ }
+ return FilePattern(fp.format_function, *new_combine_dims, **kwargs)
