Skip to content

Commit

Permalink
Merge branch 'develop' into schema-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut authored Mar 29, 2024
2 parents afef25a + 150b642 commit 65233a8
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 43 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,15 @@
"contributions": [
"bug"
]
},
{
"login": "sherbang",
"name": "sherbang",
"avatar_url": "https://avatars.githubusercontent.com/u/275015?v=4",
"profile": "https://github.com/sherbang",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ jobs:
- name: Run pyright
run: pdm run pyright

slotscheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.8"
allow-prereleases: false

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
with:
python-version: "3.8"
allow-python-prereleases: false
cache: true
cache-dependency-path: |
./pdm.lock
- name: Install dependencies
run: pdm install -G:all

- name: Run slotscheck
run: pdm run slotscheck litestar

test:
name: "test (${{ matrix.python-version }})"
strategy:
Expand Down
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ repos:
- id: ensure-dunder-all
exclude: "test*|examples*|tools"
args: ["--use-tuple"]
- repo: https://github.com/ariebovenberg/slotscheck
rev: v0.19.0
hooks:
- id: slotscheck
exclude: "test_*|docs|.github"
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.9.1"
hooks:
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ pre-commit: ## Runs pre-commit hooks; includes ruff formatting and lin
@$(PDM) run pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: slots-check
slots-check: ## Check for slots usage in classes
@echo "=> Checking for slots usage in classes"
@$(PDM) run slotscheck litestar
@echo "=> Slots check complete"

.PHONY: lint
lint: pre-commit type-check ## Run all linting
lint: pre-commit type-check slots-check ## Run all linting

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ A **huge** thanks to our sponsors:

<a href="https://docs.litestar.dev/dev/#sponsors" class="external-link" target="_blank">Check out our sponsors in the docs</a>

If you would like to support the work that we do please consider [becoming a sponsor][sponsor-github]
on [GitHub][sponsor-github] or [Open Collective][sponsor-oc].
If you would like to support the work that we do please consider [becoming a sponsor][sponsor-polar]
via [Polar.sh][sponsor-polar] (preferred), [GitHub][sponsor-github] or [Open Collective][sponsor-oc].

We also participate in pledge-based sponsorship with [Polar][sponsor-polar].
Also, exclusively with [Polar][sponsor-polar], you can engage in pledge-based sponsorships.

[sponsor-github]: https://github.com/sponsors/litestar-org
[sponsor-oc]: https://opencollective.com/litestar
Expand Down Expand Up @@ -554,6 +554,7 @@ see [the contribution guide](CONTRIBUTING.rst).
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="http://www.b-list.org/"><img src="https://avatars.githubusercontent.com/u/12384?v=4?s=100" width="100px;" alt="James Bennett"/><br /><sub><b>James Bennett</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/issues?q=author%3Aubernostrum" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sherbang"><img src="https://avatars.githubusercontent.com/u/275015?v=4?s=100" width="100px;" alt="sherbang"/><br /><sub><b>sherbang</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=sherbang" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 3 additions & 3 deletions docs/PYPI_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ A **huge** thanks to our sponsors:

<a href="https://docs.litestar.dev/dev/#sponsors" class="external-link" target="_blank">Check out our sponsors in the docs</a>

If you would like to support the work that we do please consider [becoming a sponsor][sponsor-github]
on [GitHub][sponsor-github] or [Open Collective][sponsor-oc].
If you would like to support the work that we do please consider [becoming a sponsor][sponsor-polar]
via [Polar.sh][sponsor-polar] (preferred), [GitHub][sponsor-github] or [Open Collective][sponsor-oc].

We also participate in pledge-based sponsorship with [Polar][sponsor-polar].
Also, exclusively with [Polar][sponsor-polar], you can engage in pledge-based sponsorships.

[sponsor-github]: https://github.com/sponsors/litestar-org
[sponsor-oc]: https://opencollective.com/litestar
Expand Down
5 changes: 2 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ A huge thank you to our current sponsors:
</div>

We invite organizations and individuals to join our sponsorship program.
By becoming a sponsor on platforms like `GitHub <sponsor-github_>`_
By becoming a sponsor on `Polar <sponsor-polar_>`_ (preferred), or other platforms like `GitHub <sponsor-github_>`_
and `Open Collective <sponsor-oc_>`_, you can play a pivotal role in our project's growth.

Additionally, we engage in pledge-based sponsorship opportunities through `Polar <sponsor-polar_>`_.

Also, exclusively with `Polar <sponsor-polar_>`_, you can engage in pledge-based sponsorships.

.. _sponsor-github: https://github.com/sponsors/litestar-org
.. _sponsor-oc: https://opencollective.com/litestar
Expand Down
6 changes: 0 additions & 6 deletions docs/release-notes/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
.. changelog:: 2.7.1
:date: 2024-03-22

.. change:: add default encoders for `Enums` and `EnumMeta`
:type: bugfix
:pr: 3193

This addresses an issue when serializing ``Enums`` that was reported in discord.

.. change:: replace TestClient.__enter__ return type with Self
:type: bugfix
:pr: 3194
Expand Down
4 changes: 0 additions & 4 deletions litestar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,17 @@ class Litestar(Router):
"csrf_config",
"event_emitter",
"get_logger",
"include_in_schema",
"logger",
"logging_config",
"multipart_form_part_limit",
"on_shutdown",
"on_startup",
"openapi_config",
"request_class",
"response_cache_config",
"route_map",
"signature_namespace",
"state",
"stores",
"template_engine",
"websocket_class",
"pdb_on_exception",
"experimental_features",
)
Expand Down
2 changes: 0 additions & 2 deletions litestar/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
click.rich_click.USE_MARKDOWN = False
click.rich_click.SHOW_ARGUMENTS = True
click.rich_click.GROUP_ARGUMENTS_OPTIONS = True
click.rich_click.SHOW_ARGUMENTS = True
click.rich_click.GROUP_ARGUMENTS_OPTIONS = True
click.rich_click.STYLE_ERRORS_SUGGESTION = "magenta italic"
click.rich_click.ERRORS_SUGGESTION = ""
click.rich_click.ERRORS_EPILOGUE = ""
Expand Down
2 changes: 0 additions & 2 deletions litestar/contrib/opentelemetry/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
class OpenTelemetryInstrumentationMiddleware(AbstractMiddleware):
"""OpenTelemetry Middleware."""

__slots__ = ("open_telemetry_middleware",)

def __init__(self, app: ASGIApp, config: OpenTelemetryConfig) -> None:
"""Middleware that adds OpenTelemetry instrumentation to the application.
Expand Down
3 changes: 0 additions & 3 deletions litestar/dto/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ class MappingType(CompositeType):
@dataclass(frozen=True)
class TransferDTOFieldDefinition(DTOFieldDefinition):
__slots__ = (
"default_factory",
"dto_field",
"model_name",
"is_excluded",
"is_partial",
"serialization_name",
Expand Down
5 changes: 2 additions & 3 deletions litestar/handlers/websocket_handlers/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ class WebsocketListenerRouteHandler(WebsocketRouteHandler):
"connection_accept_handler": "Callback to accept a WebSocket connection. By default, calls WebSocket.accept",
"on_accept": "Callback invoked after a WebSocket connection has been accepted",
"on_disconnect": "Callback invoked after a WebSocket connection has been closed",
"weboscket_class": "WebSocket class",
"_connection_lifespan": None,
"_handle_receive": None,
"_handle_send": None,
"_receive_handler": None,
"_receive_mode": None,
"_send_handler": None,
"_send_mode": None,
}

Expand Down
2 changes: 2 additions & 0 deletions litestar/handlers/websocket_handlers/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WebsocketRouteHandler(BaseRouteHandler):
Use this decorator to decorate websocket handler functions.
"""

__slots__ = ("websocket_class",)

def __init__(
self,
path: str | list[str] | None = None,
Expand Down
2 changes: 2 additions & 0 deletions litestar/middleware/compression/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class CompressionFacade(Protocol):
"""A unified facade offering a uniform interface for different compression libraries."""

__slots__ = ()

encoding: ClassVar[str]
"""The encoding of the compression."""

Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
class CORSMiddleware(AbstractMiddleware):
"""CORS Middleware."""

__slots__ = ("config",)

def __init__(self, app: ASGIApp, config: CORSConfig) -> None:
"""Middleware that adds CORS validation to the application.
Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
class LoggingMiddleware(AbstractMiddleware):
"""Logging middleware."""

__slots__ = ("config", "logger", "request_extractor", "response_extractor", "is_struct_logger")

logger: Logger

def __init__(self, app: ASGIApp, config: LoggingMiddlewareConfig) -> None:
Expand Down
2 changes: 0 additions & 2 deletions litestar/middleware/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class CacheObject:
class RateLimitMiddleware(AbstractMiddleware):
"""Rate-limiting middleware."""

__slots__ = ("app", "check_throttle_handler", "max_requests", "unit", "request_quota", "config")

def __init__(self, app: ASGIApp, config: RateLimitConfig) -> None:
"""Initialize ``RateLimitMiddleware``.
Expand Down
2 changes: 2 additions & 0 deletions litestar/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def to_openapi_schema(self, field_definition: FieldDefinition, schema_creator: S
class OpenAPISchemaPlugin(OpenAPISchemaPluginProtocol):
"""Plugin to extend the support of OpenAPI schema generation for non-library types."""

__slots__ = ()

@staticmethod
def is_plugin_supported_type(value: Any) -> bool:
"""Given a value of indeterminate type, determine if this value is supported by the plugin.
Expand Down
4 changes: 4 additions & 0 deletions litestar/stores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
class Store(ABC):
"""Thread and process safe asynchronous key/value store."""

__slots__ = ()

@abstractmethod
async def set(self, key: str, value: str | bytes, expires_in: int | timedelta | None = None) -> None:
"""Set a value.
Expand Down Expand Up @@ -97,6 +99,8 @@ class NamespacedStore(Store):
should be isolated.
"""

__slots__ = ("namespace",)

@abstractmethod
def with_namespace(self, namespace: str) -> Self:
"""Return a new instance of :class:`NamespacedStore`, which exists in a child namespace of the current namespace.
Expand Down
7 changes: 6 additions & 1 deletion litestar/stores/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
class RedisStore(NamespacedStore):
"""Redis based, thread and process safe asynchronous key/value store."""

__slots__ = ("_redis",)
__slots__ = (
"_delete_all_script",
"_get_and_renew_script",
"_redis",
"handle_client_shutdown",
)

def __init__(
self, redis: Redis, namespace: str | None | EmptyType = Empty, handle_client_shutdown: bool = False
Expand Down
2 changes: 1 addition & 1 deletion litestar/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _parse_metadata(value: Any, is_sequence_container: bool, extra: dict[str, An
example_list: list[Any] | None
if example := extra.pop("example", None):
example_list = [Example(value=example)]
elif examples := getattr(value, "examples", None):
elif examples := (extra.pop("examples", None) or getattr(value, "examples", None)):
example_list = [Example(value=example) for example in cast("list[str]", examples)]
else:
example_list = None
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ reportUnnecessaryTypeIgnoreComments = true

[tool.slotscheck]
strict-imports = false
exclude-classes = """
(
# github.com/python/cpython/pull/106771
(^litestar.events.emitter:BaseEventEmitterBackend)
)
"""

[tool.ruff]
lint.select = [
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_contrib/test_pydantic/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,26 @@ class Model(pydantic_v2.BaseModel):
assert value.examples == ["example"]


def test_create_schema_for_field_v2__examples() -> None:
class Model(pydantic_v2.BaseModel):
value: str = pydantic_v2.Field(
title="title", description="description", max_length=16, json_schema_extra={"examples": ["example"]}
)

schema = get_schema_for_field_definition(
FieldDefinition.from_kwarg(name="Model", annotation=Model), plugins=[PydanticSchemaPlugin()]
)

assert schema.properties

value = schema.properties["value"]

assert isinstance(value, Schema)
assert value.description == "description"
assert value.title == "title"
assert value.examples == ["example"]


@pytest.mark.parametrize("with_future_annotations", [True, False])
def test_create_schema_for_pydantic_model_with_annotated_model_attribute(
with_future_annotations: bool, create_module: "Callable[[str], ModuleType]", pydantic_version: PydanticVersion
Expand Down

0 comments on commit 65233a8

Please sign in to comment.