Skip to content

Commit

Permalink
list(dependencies or []) -> dependencies or []
Browse files Browse the repository at this point in the history
As minor a side effect, when concatenating lists of dependencies it now uses `list(a).extend(b)` instead of `a.copy().extend(b)`, as
dependencies are defined to be a `Sequence` instead of a list, and .extend is only supported with lists
  • Loading branch information
paulo-raca committed Feb 10, 2022
1 parent 440cc9d commit 10dc6e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fastapi/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(
) -> None:
self.path = path
self.endpoint = endpoint
self.dependencies = list(dependencies or [])
self.dependencies = dependencies or []
self.name = get_name(endpoint) if name is None else name
self.path_regex, self.path_format, self.param_convertors = compile_path(path)
self.dependant = get_dependant(path=path, call=self.endpoint)
Expand Down Expand Up @@ -373,7 +373,7 @@ def __init__(
self.secure_cloned_response_field = None
self.status_code = status_code
self.tags = tags or []
self.dependencies = list(dependencies or [])
self.dependencies = dependencies or []
self.summary = summary
self.description = description or inspect.cleandoc(self.endpoint.__doc__ or "")
# if a "form feed" character (page break) is found in the description text,
Expand Down Expand Up @@ -471,7 +471,7 @@ def __init__(
), "A path prefix must not end with '/', as the routes will start with '/'"
self.prefix = prefix
self.tags: List[Union[str, Enum]] = tags or []
self.dependencies = list(dependencies or [])
self.dependencies = dependencies or []
self.deprecated = deprecated
self.include_in_schema = include_in_schema
self.responses = responses or {}
Expand Down Expand Up @@ -520,7 +520,7 @@ def add_api_route(
current_tags = self.tags.copy()
if tags:
current_tags.extend(tags)
current_dependencies = self.dependencies.copy()
current_dependencies = list(self.dependencies)
if dependencies:
current_dependencies.extend(dependencies)
current_callbacks = self.callbacks.copy()
Expand Down Expand Up @@ -621,7 +621,7 @@ def add_api_websocket_route(
dependencies: Optional[Sequence[params.Depends]] = None,
name: Optional[str] = None,
) -> None:
current_dependencies = self.dependencies.copy()
current_dependencies = list(self.dependencies)
if dependencies:
current_dependencies.extend(dependencies)

Expand Down

0 comments on commit 10dc6e9

Please sign in to comment.