Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_from_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def fixture_file_path(filename: str) -> str:
return os.path.join(absolute_dir, "fixtures", filename)


ExampleVariables = uritemplate.variable.VariableValueDict
ExampleVariables = uritemplate.variable.VariableValueMapping
ExampleTemplatesAndResults = t.List[t.Tuple[str, t.Union[str, t.List[str]]]]


Expand Down
12 changes: 7 additions & 5 deletions tests/test_uritemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

def merge_dicts(
*args: t.Union[
variable.VariableValueDict, t.Dict[str, str], t.Dict[str, t.List[str]]
variable.VariableValueMapping,
t.Dict[str, str],
t.Dict[str, t.List[str]],
]
) -> variable.VariableValueDict:
) -> variable.VariableValueMapping:
d: t.Dict[str, variable.VariableValue] = {}
for arg in args:
d.update(arg)
return d


ExampleVariables = variable.VariableValueDict
ExampleVariables = variable.VariableValueMapping
ExampleTemplatesAndResults = t.List[t.Tuple[str, t.Union[str, t.List[str]]]]


Expand Down Expand Up @@ -582,7 +584,7 @@ def test_hashability(self) -> None:
self.assertEqual(d, {t: 2})

def test_no_mutate(self) -> None:
args: variable.VariableValueDict = {}
args: variable.VariableValueMapping = {}
t = URITemplate("")
t.expand(args, key=1)
self.assertEqual(args, {})
Expand Down Expand Up @@ -635,7 +637,7 @@ def test_variables(self) -> None:


class TestNativeTypeSupport(unittest.TestCase):
context: variable.VariableValueDict = {
context: variable.VariableValueMapping = {
"zero": 0,
"one": 1,
"digits": list(range(10)),
Expand Down
4 changes: 2 additions & 2 deletions uritemplate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def expand(
uri: str,
var_dict: t.Optional[variable.VariableValueDict] = None,
var_dict: t.Optional[variable.VariableValueMapping] = None,
**kwargs: variable.VariableValue,
) -> str:
"""Expand the template with the given parameters.
Expand Down Expand Up @@ -46,7 +46,7 @@ def expand(

def partial(
uri: str,
var_dict: t.Optional[variable.VariableValueDict] = None,
var_dict: t.Optional[variable.VariableValueMapping] = None,
**kwargs: variable.VariableValue,
) -> URITemplate:
"""Partially expand the template with the given parameters.
Expand Down
14 changes: 7 additions & 7 deletions uritemplate/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@


def _merge(
var_dict: t.Optional[variable.VariableValueDict],
overrides: variable.VariableValueDict,
) -> variable.VariableValueDict:
var_dict: t.Optional[variable.VariableValueMapping],
overrides: variable.VariableValueMapping,
) -> variable.VariableValueMapping:
if var_dict:
opts = var_dict.copy()
opts = dict(var_dict)
opts.update(overrides)
return opts
return overrides
Expand Down Expand Up @@ -97,7 +97,7 @@ def __hash__(self) -> int:
return hash(self.uri)

def _expand(
self, var_dict: variable.VariableValueDict, replace: bool
self, var_dict: variable.VariableValueMapping, replace: bool
) -> str:
if not self.variables:
return self.uri
Expand All @@ -121,7 +121,7 @@ def replace_partial(match: "re.Match[str]") -> str:

def expand(
self,
var_dict: t.Optional[variable.VariableValueDict] = None,
var_dict: t.Optional[variable.VariableValueMapping] = None,
**kwargs: variable.VariableValue,
) -> str:
"""Expand the template with the given parameters.
Expand All @@ -148,7 +148,7 @@ def expand(

def partial(
self,
var_dict: t.Optional[variable.VariableValueDict] = None,
var_dict: t.Optional[variable.VariableValueMapping] = None,
**kwargs: variable.VariableValue,
) -> "URITemplate":
"""Partially expand the template with the given parameters.
Expand Down
4 changes: 2 additions & 2 deletions uritemplate/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
t.Tuple[str, ScalarVariableValue],
ScalarVariableValue,
]
VariableValueDict = t.Dict[str, VariableValue]
VariableValueMapping = t.Mapping[str, VariableValue]


_UNRESERVED_CHARACTERS: t.Final[str] = (
Expand Down Expand Up @@ -451,7 +451,7 @@ def _string_expansion(
return self.operator.quote(value)

def expand(
self, var_dict: t.Optional[VariableValueDict] = None
self, var_dict: t.Optional[VariableValueMapping] = None
) -> t.Mapping[str, str]:
"""Expand the variable in question.

Expand Down