Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve orm.query #70

Merged
merged 2 commits into from
Apr 22, 2021
Merged

Conversation

bryanforbes
Copy link
Contributor

Description

Improve typings for orm.query. Fixes #66.

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

def yield_per(self, count: Any) -> None: ...
def get(self, ident: Any): ...
) -> _TQuery: ...
def yield_per(self: _TQuery, count: Any) -> _TQuery: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count should an int I think

) -> Any: ...
def merge_result(self, iterator: Any, load: bool = ...) -> Any: ...
def exists(self) -> Exists: ...
def count(self) -> Any: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it return int?

@property
def session(self): ...
def session(self) -> Any: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be session protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional[_SessionProtocol], but yes

@@ -406,7 +406,9 @@ class Session(_SessionClassMethods):
binds: Optional[Mapping[Any, Union[Connection, Engine]]] = ...,
enable_baked_queries: bool = ...,
info: Optional[Mapping[Any, Any]] = ...,
query_cls: Optional[Union[Query, Callable[..., Query]]] = ...,
query_cls: Optional[
Union[Query[Any], Callable[..., Query[Any]]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be Type[Query[Any]]?

@@ -473,7 +475,7 @@ class Session(_SessionClassMethods):
_sa_skip_events: Optional[Any] = ...,
_sa_skip_for_implicit_returning: bool = ...,
) -> Union[Connection, Engine]: ...
def query(self, *entities: Any, **kwargs: Any) -> Query: ...
def query(self, *entities: Any, **kwargs: Any) -> Query[Any]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make an overload here similar to this:
def query(self, entities: Type[_T], **kwargs: Any) -> Query[_T]?

not sure if others are also applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's right and it's the reason I left Query.__init__ basically untyped. It uses coerce.expect(), so it can be a lot of different things.

Copy link
Member

@CaselIT CaselIT Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without is I don't think we support the case: things = session.query(Thing).all() and things is not List[Thing], no?

@CaselIT CaselIT merged commit 88567bf into sqlalchemy:master Apr 22, 2021
@bryanforbes bryanforbes deleted the improve-orm-query branch April 22, 2021 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filter and options methods of Query object aren't correctly detected
2 participants