-
Notifications
You must be signed in to change notification settings - Fork 234
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
Bad type in get_or_create docs #371
Comments
@eranzim This representation is correct as it takes tuple of dictionaries.
This gives us
which is python behaviour for Non-Keyword Arguments |
I understand, and this makes sense that args would be a tuple inside the function. Does that mean that there is a bug in PyCharm? Because even in the example you gave, it will issue a warning if I add |
@eranzim Thanks, it is worth the clarification. Yes, the type right there would be |
@eranzim This has now been changed to:
Not sure about what PyCharm uses for code analysis and whether this should be looked any further though. |
As Python always packages function arguments as a tuple when function uses *some_name to declare an undetermined number arguments, the convention seems to be to use any documented type (docstring :type) as the type of tuple's contained elements. PEP 484 suggests that I reached out to JetBrains regarding this and this is their response: "one is not really expected to annotate arbitrary (*args) or default (**kwargs) arguments as tuples or dicts. As you said they are always tuples or dicts so the static analysis tools (or engineers reading the code) always know the collection type. The part of interest is the tuple/dict items type. See a relevant part of PEP 484 https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values I guess we can extrapolate the same logic to type annotations in docstrings." Accordingly, what makes sense is to change get_or_create and create_or_update methods to
|
I believe there is a mistake in the docs of get_or_create class method in core.py. They say:
Passing a tuple results in an error (
AttributeError: 'tuple' object has no attribute 'get'
)... I believe it should be dict, like the description says.Being as it is, PyCharm falsely alerts me I'm passing a wrong type in all my get_or_create calls.
Thanks!
The text was updated successfully, but these errors were encountered: