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

Fix typing - :type kwargs: dict is not correct #7422

Closed
wants to merge 1 commit into from

Conversation

retnikt
Copy link

@retnikt retnikt commented Feb 22, 2019

When typing Python code, the special *args and **kwargs params are typed based on their contents, not what they actually are (a tuple, and a dict) e.g.

def foo(thing: int, *args: str):
    ...
def bar(thing: int, *args: str, **kwargs: Union[int, float]):
    ...

bar(-3, "G", spam=80, eggs=4.4)
foo(44, "abc", "xyz")

And in this case, the types are passed to a different func (Query.__init__) which has specific arguments, so it is best to not give **kwargs a type, or, better, copy the parameters of that function (but I haven't done this here).
This also applies to Transaction.
PS I know this is a stupidly minor change but it annoys me, having to write noinspection PyTypeChecker before every datastore query.
😄

When typing Python code, the special `*args` and `**kwargs` params are typed based on their contents, e.g.
```python
def foo(thing: int, *args: str):
    ...
def bar(thing: int, *args: str, **kwargs: Union[int, float]):
    ...

bar(-3, "G", spam=80, eggs=4.4)
foo(44, "abc", "xyz")```

And in this case, the types are passed to a different func (`Query.__init__`) which has specific arguments, so it is best to not give **kwargs a type, or, better, copy the parameters of that function (but I haven't done this here).
This also applies to `Transaction`.
PS I know this is a stupidly minor change but it annoys me, having to write `noinspection PyTypeChecker` before every datastore query.
:smile:
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 22, 2019
@tseaver tseaver added the api: datastore Issues related to the Datastore API. label Feb 22, 2019
@tseaver
Copy link
Contributor

tseaver commented Feb 22, 2019

@crwilcox I'm -1 on this change myself, but will leave it to you to decide: if we are going to change how we document kwargs here, we should make the change throughout the codebase.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 4, 2019
@crwilcox
Copy link
Contributor

I spent some time researching. This is also how mypy interprets types. I agree though @tseaver, we likely need to do this more broadly.

@crwilcox
Copy link
Contributor

crwilcox commented Jul 1, 2019

Thanks for filing this @retnikt. Closing this in favor of a pr I just opened which will address this more broadly.

#8546

@crwilcox crwilcox closed this Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants