Satisfy linters and type checkers#9
Satisfy linters and type checkers#9srnnkls wants to merge 2 commits intoclaude/fix-thread-safety-011CUVadQR4koPDAzN6K78zXfrom
Conversation
LRU caches - Implement snapshot semantics; return primitives directly Add mapping property to expose dict methods without field collisions - Add refresh() and unwrap(); implement get, __contains__, __reversed__ - Add bounded LRU caches for schemas, proxy types, and attrs with locks - Improve subschema extraction (nullable, defs, chain, unions, tuples, lists, dict) - Support serializer functions with info_arg; avoid mutating schema type - Do not set __pydantic_validator__ on child proxies - Use Sequence for serialized data; wrap dicts in MappingProxyType
issues - Add pyright and ruff to dev dependencies and lockfile - Tighten typing across codebase for pyright: - Use runtime_checkable on Protocols - Refine template decorators to return type[T] - Apply pydantic_dataclass directly to preserve class types - Add targeted pyright ignore comments for dynamic attrs/returns - Update transform utilities to access dynamic template attrs safely - Clean up tests: adopt TypeAlias/Annotated, remove unused imports/vars No functional behavior changes; improves static type safety and linting compliance
Summary of ChangesHello @srnnkls, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the code quality and maintainability of the project by integrating 'pyright' and 'ruff' for static analysis. It includes a substantial refactor of the 'SerializationProxy' class to enhance its Pydantic 'CoreSchema' handling, optimize caching mechanisms, and provide a more ergonomic API. Additionally, various type-hinting adjustments and linter compliance fixes have been applied throughout the codebase to satisfy the newly introduced static analysis tools. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request does an excellent job of satisfying linters and type checkers, as the title suggests. The changes go beyond simple style fixes, introducing significant improvements to thread safety, robustness, and performance, particularly within the SerializationProxy. The addition of proper locking for cache access and the implementation of LRU eviction policies are great enhancements. The type hints are now much more accurate, and the codebase is more solid as a result. I've identified a few areas for further improvement: a bug that causes a crash when slicing a proxy object, and a couple of opportunities to make type hints even more precise. Overall, this is a very high-quality contribution.
| # implement this correctly than to just keep piggybacking on pydantic's CoreSchema | ||
| # internals. | ||
| def _extract_subschema(schema: CoreSchema, name: str) -> CoreSchema: | ||
| def _extract_subschema(schema: CoreSchema, name_or_idx) -> CoreSchema: |
There was a problem hiding this comment.
For better type safety and clarity, it's a good practice to add a type hint for the name_or_idx parameter. Based on its usage and the docstring, it appears to be a str or an int.
| def _extract_subschema(schema: CoreSchema, name_or_idx) -> CoreSchema: | |
| def _extract_subschema(schema: CoreSchema, name_or_idx: str | int) -> CoreSchema: |
| return cls | ||
|
|
||
|
|
||
| def with_(cls_or_instance: type[_T] | _T, **kwargs: Unpack[TemplateKwargs]) -> type[_T]: |
There was a problem hiding this comment.
The return type hint for this function appears to be incorrect. It's declared as type[_T], but when an instance is passed as cls_or_instance, the function returns a new instance of _T (on line 65), not a type. This causes a type mismatch that is currently suppressed with pyright: ignore[reportReturnType].
The return type should be type[_T] | _T to accurately reflect both execution paths. For even better type inference, you could consider using @overload to define separate signatures for when a type is passed versus when an instance is passed.
| def with_(cls_or_instance: type[_T] | _T, **kwargs: Unpack[TemplateKwargs]) -> type[_T]: | |
| def with_(cls_or_instance: type[_T] | _T, **kwargs: Unpack[TemplateKwargs]) -> type[_T] | _T: |
No description provided.