diff --git a/fastapi/routing.py b/fastapi/routing.py index a4c25c159..e8e5ba788 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -500,7 +500,9 @@ class APIRouter(routing.Router): ), "A path prefix must not end with '/', as the routes will start with '/'" self.prefix = prefix if tags: - assert not isinstance(tags, str), """tags should not be a string: please use ["tag"] instead of "tag".""" + assert not isinstance( + tags, str + ), """tags should not be a string: please use ["tag"] instead of "tag".""" self.tags: List[Union[str, Enum]] = tags or [] self.dependencies = list(dependencies or []) or [] self.deprecated = deprecated @@ -554,7 +556,9 @@ class APIRouter(routing.Router): ) current_tags = self.tags.copy() if tags: - assert not isinstance(tags, str), """tags should not be a string: please use ["tag"] instead of "tag".""" + assert not isinstance( + tags, str + ), """tags should not be a string: please use ["tag"] instead of "tag".""" current_tags.extend(tags) current_dependencies = self.dependencies.copy() if dependencies: @@ -719,7 +723,9 @@ class APIRouter(routing.Router): ) current_tags = [] if tags: - assert not isinstance(tags, str), """tags should not be a string: please use ["tag"] instead of "tag".""" + assert not isinstance( + tags, str + ), """tags should not be a string: please use ["tag"] instead of "tag".""" current_tags.extend(tags) if route.tags: current_tags.extend(route.tags) diff --git a/tests/test_tags.py b/tests/test_tags.py index f38d84223..e115b3e3d 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -6,10 +6,12 @@ def test_string_is_invalid_in_router_tags(): with pytest.raises(AssertionError): router = APIRouter(tags="test") + def test_string_is_invalid_in_router_route_tags(): router = APIRouter() with pytest.raises(AssertionError): + @router.get("", tags="test") def test(): ... @@ -24,4 +26,4 @@ def test_string_is_invalid_in_include_router_tags(): ... with pytest.raises(AssertionError): - app.include_router(router, prefix="/test", tags="test") \ No newline at end of file + app.include_router(router, prefix="/test", tags="test")