Skip to content

Commit

Permalink
docs: fix python ast, run pre-commit, rebase on latest docs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobCoffee committed Apr 27, 2024
1 parent 6661e78 commit 24637d9
Show file tree
Hide file tree
Showing 235 changed files with 444 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


@get("/")
def handler(state: State) -> None: ...
def handler(state: State) -> None: ...
Empty file.
2 changes: 1 addition & 1 deletion docs/examples/caching/caching_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


@get("/cached-path", cache=120) # seconds
def my_cached_handler() -> str: ...
def my_cached_handler() -> str: ...
2 changes: 1 addition & 1 deletion docs/examples/caching/caching_forever.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


@get("/cached-path", cache=CACHE_FOREVER) # seconds
def my_cached_handler() -> str: ...
def my_cached_handler() -> str: ...
4 changes: 2 additions & 2 deletions docs/examples/caching/caching_key_builder_specific_route.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from litestar import Litestar, Request, get
from litestar import Request, get


def key_builder(request: Request) -> str:
return request.url.path + request.headers.get("my-header", "")


@get("/cached-path", cache=True, cache_key_builder=key_builder)
def cached_handler() -> str: ...
def cached_handler() -> str: ...
2 changes: 1 addition & 1 deletion docs/examples/caching/caching_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


@get("/cached-path", cache=True)
def my_cached_handler() -> str: ...
def my_cached_handler() -> str: ...
2 changes: 1 addition & 1 deletion docs/examples/caching/caching_storage_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

redis_store = RedisStore(url="redis://localhost/", port=6379, db=0)

cache_config = ResponseCacheConfig(store=redis_store)
cache_config = ResponseCacheConfig(store=redis_store)
2 changes: 1 addition & 1 deletion docs/examples/channels/allowing_arbitrary_channels.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from litestar.channels import ChannelsPlugin

channels_plugin = ChannelsPlugin(..., arbitrary_channels_allowed=True)
channels_plugin = ChannelsPlugin(..., arbitrary_channels_allowed=True)
2 changes: 1 addition & 1 deletion docs/examples/channels/backoff_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
backend=MemoryChannelsBackend(),
max_backlog=1000,
backlog_strategy="backoff",
)
)
2 changes: 1 addition & 1 deletion docs/examples/channels/eviction_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
backend=MemoryChannelsBackend(),
max_backlog=1000,
backlog_strategy="dropleft",
)
)
2 changes: 1 addition & 1 deletion docs/examples/channels/passing_channels_explicitly.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from litestar.channels import ChannelsPlugin

channels_plugin = ChannelsPlugin(..., channels=["foo", "bar"])
channels_plugin = ChannelsPlugin(..., channels=["foo", "bar"])
2 changes: 1 addition & 1 deletion docs/examples/channels/publish_data.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
channels.publish({"message": "Hello"}, "general")
channels.publish({"message": "Hello"}, "general")
2 changes: 1 addition & 1 deletion docs/examples/channels/subscribe_method_context_manager.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
async with channels.start_subscription(["foo", "bar"]) as subscriber:
... # do some stuff here
... # do some stuff here
2 changes: 1 addition & 1 deletion docs/examples/channels/subscribe_method_manually.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
try:
... # do some stuff here
finally:
await channels.unsubscribe(subscriber)
await channels.unsubscribe(subscriber)
4 changes: 2 additions & 2 deletions docs/examples/channels/unsubscribe_method_context_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
async with channels.start_subscription(["foo", "bar"]) as subscriber:
... # do some stuff here
await channels.unsubscribe(subscriber, ["foo"])
# do some stuff here
await channels.unsubscribe(subscriber, ["foo"])
4 changes: 2 additions & 2 deletions docs/examples/channels/unsubscribe_method_manually.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subscriber = await channels.subscribe(["foo", "bar"])
... # do some stuff here
await channels.unsubscribe(subscriber, ["foo"])
# do some stuff here
await channels.unsubscribe(subscriber, ["foo"])
3 changes: 2 additions & 1 deletion docs/examples/cli/app_instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click

from litestar import Litestar


@click.command()
def my_command(app: Litestar) -> None: ...
def my_command(app: Litestar) -> None: ...
12 changes: 6 additions & 6 deletions docs/examples/cli/entry_points.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from setuptools import setup

setup(
name="my-litestar-plugin",
...,
entry_points={
"litestar.commands": ["my_command=my_litestar_plugin.cli:main"],
},
)
name="my-litestar-plugin",
# ..., other setup arguments
entry_points={
"litestar.commands": ["my_command=my_litestar_plugin.cli:main"],
},
)
2 changes: 1 addition & 1 deletion docs/examples/cli/info.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar info
litestar info
5 changes: 3 additions & 2 deletions docs/examples/cli/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from click import Group

from litestar import Litestar
from litestar.plugins import CLIPluginProtocol
from click import Group


class CLIPlugin(CLIPluginProtocol):
Expand All @@ -10,4 +11,4 @@ def is_debug_mode(app: Litestar):
print(app.debug)


app = Litestar(plugins=[CLIPlugin()])
app = Litestar(plugins=[CLIPlugin()])
2 changes: 1 addition & 1 deletion docs/examples/cli/poetry.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool.poetry.plugins."litestar.commands"]
my_command = "my_litestar_plugin.cli:main"
my_command = "my_litestar_plugin.cli:main"
2 changes: 1 addition & 1 deletion docs/examples/cli/reload_dir.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar run --reload-dir=. --reload-dir=../other-library/src
litestar run --reload-dir=. --reload-dir=../other-library/src
2 changes: 1 addition & 1 deletion docs/examples/cli/reload_dir_multiple_directories.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LITESTAR_RELOAD_DIRS=.,../other-library/src
LITESTAR_RELOAD_DIRS=.,../other-library/src
2 changes: 1 addition & 1 deletion docs/examples/cli/reload_exclude_multiple_directories.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LITESTAR_RELOAD_EXCLUDES=*.py,*.yml
LITESTAR_RELOAD_EXCLUDES=*.py,*.yml
2 changes: 1 addition & 1 deletion docs/examples/cli/reload_include.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar run --reload-include="*.rst" --reload-include="*.yml"
litestar run --reload-include="*.rst" --reload-include="*.yml"
2 changes: 1 addition & 1 deletion docs/examples/cli/reload_include_multiple_directories.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LITESTAR_RELOAD_INCLUDES=*.rst,*.yml
LITESTAR_RELOAD_INCLUDES=*.rst,*.yml
2 changes: 1 addition & 1 deletion docs/examples/cli/routes.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar routes
litestar routes
2 changes: 1 addition & 1 deletion docs/examples/cli/run.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar run
litestar run
2 changes: 1 addition & 1 deletion docs/examples/cli/sessions_clear.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar sessions clear
litestar sessions clear
2 changes: 1 addition & 1 deletion docs/examples/cli/ssl.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar run --ssl-certfile=certs/cert.pem --ssl-keyfile=certs/key.pem
litestar run --ssl-certfile=certs/cert.pem --ssl-keyfile=certs/key.pem
2 changes: 1 addition & 1 deletion docs/examples/cli/typescript_schema.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
litestar schema typescript
litestar schema typescript
2 changes: 1 addition & 1 deletion docs/examples/cli/typescript_schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export namespace API {
// ...
}
}
2 changes: 1 addition & 1 deletion docs/examples/cli/typescript_schema_namespace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export namespace MyNamespace {
// ...
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass

from litestar import get
from litestar.dto import DTOConfig, DataclassDTO
from litestar.dto import DataclassDTO, DTOConfig


@dataclass
Expand All @@ -16,4 +16,4 @@ class MyDTO(DataclassDTO[MyType]):

@get(dto=MyDTO)
async def handler() -> MyType:
return MyType(some_field="some value", another_field=42)
return MyType(some_field="some value", another_field=42)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from litestar.dto import DTOConfig, DataclassDTO

from litestar.dto import DataclassDTO, DTOConfig


@dataclass
Expand All @@ -8,4 +9,4 @@ class Foo:


class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=False)
config = DTOConfig(experimental_codegen_backend=False)
2 changes: 1 addition & 1 deletion docs/examples/data_transfer_objects/enabling_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from litestar import Litestar
from litestar.config.app import ExperimentalFeatures

app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN])
app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN])
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
@dataclass
class WithCount(Generic[T]):
count: int
data: List[T]
data: List[T]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from advanced_alchemy.dto import SQLAlchemyDTO

from litestar.dto import DTOConfig


class UserDTO(SQLAlchemyDTO[User]):
config = DTOConfig(exclude={"password", "created_at"})
config = DTOConfig(exclude={"password", "created_at"})
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def get_users() -> WithCount[User]:
created_at=datetime.now(),
),
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pets.0.id",
"pets.0.user_id",
}
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from advanced_alchemy.dto import SQLAlchemyDTO

from litestar.dto import DTOConfig


class UserDTO(SQLAlchemyDTO[User]):
config = DTOConfig(exclude={"password", "created_at"})
config = DTOConfig(exclude={"password", "created_at"})
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def get_users() -> ClassicPagination[User]:
created_at=datetime.now(),
),
],
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from advanced_alchemy.dto import SQLAlchemyDTO

from litestar.dto import DTOConfig


class UserDTO(SQLAlchemyDTO[User]):
config = DTOConfig(exclude={"password", "created_at"})
config = DTOConfig(exclude={"password", "created_at"})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from litestar import get, Response
from litestar import Response, get


@get("/users", dto=UserDTO, sync_to_thread=False)
Expand All @@ -11,4 +11,4 @@ def get_users() -> Response[User]:
created_at=datetime.now(),
),
headers={"X-Total-Count": "1"},
)
)
5 changes: 3 additions & 2 deletions docs/examples/data_transfer_objects/individual_dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from litestar.dto import DTOConfig, DataclassDTO

from litestar.dto import DataclassDTO, DTOConfig


@dataclass
Expand All @@ -8,4 +9,4 @@ class Foo:


class FooDTO(DataclassDTO[Foo]):
config = DTOConfig(experimental_codegen_backend=True)
config = DTOConfig(experimental_codegen_backend=True)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
app = Litestar(pdb_on_exception=True)
app = Litestar(pdb_on_exception=True)
38 changes: 18 additions & 20 deletions docs/examples/dependency_injection/dependency_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from litestar import Controller, Router, Litestar, get
from litestar import Controller, Litestar, Router, get
from litestar.di import Provide


Expand All @@ -15,30 +15,28 @@ async def int_fn() -> int: ...


class MyController(Controller):
path = "/controller"
# on the controller
dependencies = {"controller_dependency": Provide(list_fn)}
path = "/controller"
# on the controller
dependencies = {"controller_dependency": Provide(list_fn)}

# on the route handler
@get(path="/handler", dependencies={"local_dependency": Provide(int_fn)})
def my_route_handler(
self,
app_dependency: bool,
router_dependency: dict,
controller_dependency: list,
local_dependency: int,
) -> None: ...
# on the route handler
@get(path="/handler", dependencies={"local_dependency": Provide(int_fn)})
def my_route_handler(
self,
app_dependency: bool,
router_dependency: dict,
controller_dependency: list,
local_dependency: int,
) -> None: ...

# on the router
# on the router


my_router = Router(
path="/router",
dependencies={"router_dependency": Provide(dict_fn)},
route_handlers=[MyController],
path="/router",
dependencies={"router_dependency": Provide(dict_fn)},
route_handlers=[MyController],
)

# on the app
app = Litestar(
route_handlers=[my_router], dependencies={"app_dependency": Provide(bool_fn)}
)
app = Litestar(route_handlers=[my_router], dependencies={"app_dependency": Provide(bool_fn)})
Loading

0 comments on commit 24637d9

Please sign in to comment.