-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes function
to key
in docs of wrap_numbers()
#1993
base: master
Are you sure you want to change the base?
Conversation
Previously the wording was quite confusing: `name` is not a `function` (in a CPython's sense, like `Callable[...]`) and never used like one. I've changed the wording to be just `key`, which `name` is. Maybe there are better ways to describe it? Context: we are working on type stubs for `psutil` and found this description quite confusing python/typeshed#6104 (comment)
Mmm... interesting. As for the bikeshedding around naming: personally I think the wording is correct, in that it explicitly states that the argument "name" refers to a function name, and not a callable, otherwise the argument would have been called "fun" or something. But then again, I wrote that, so I suppose there's some inevitable bias. Since you're closer to description from a typing perspective than I am, I'll trust your judgement and merge your PR. Regardless, I'm interested in what your doing there. I noticed https://github.com/python/typeshed/blob/a9227ed98589bf960b1c9ee2da69890171f8dfd1/stubs/psutil/psutil/__init__.pyi. Can something like this be included in psutil itself? I'm not familiar with PEP 561, so I'm not sure. Also, while I'm at it, I have an advice about https://github.com/python/typeshed/blob/a9227ed98589bf960b1c9ee2da69890171f8dfd1/stubs/psutil/psutil/__init__.pyi: I think you should avoid relying on platform logic to check whether something is available as in: if sys.platform == "linux":
from ._pslinux import (
IOPRIO_CLASS_BE as IOPRIO_CLASS_BE,
IOPRIO_CLASS_IDLE as IOPRIO_CLASS_IDLE,
IOPRIO_CLASS_NONE as IOPRIO_CLASS_NONE,
IOPRIO_CLASS_RT as IOPRIO_CLASS_RT,
) ...because:
I would recommend using from psutil import __all__
if 'IOPRIO_CLASS_BE' in __all__:
from psutil import IOPRIO_CLASS_BE |
Thanks a lot for the detailed response!
So,
Yes! We can add this to
There are several ways to store annotations within the source code:
What do you think? If you want, I can send a PR with annotations I wrote for
Unfortunatelly, we have to 😞 We cannot use something like you've proposed: from psutil import __all__
if 'IOPRIO_CLASS_BE' in __all__:
from psutil import IOPRIO_CLASS_BE For several reasons:
import sys
__all__ = []
if sys.platform == 'darwin':
x = 1
__all__.append('x')
raise ValueError('Code bellow is not reachable')
x: str
|
Yeah, good idea. Please let's stick with
Oh! Understood.
Correct. We go as far back as Python 2.6!
Can annotations be added to function docstrings instead of being appended as EOL comments?
If 2) don't allow to put annotations into docstrings, then I'm keen on thinking this would probably be the best compromise. |
The best we can do is: def embezzle(self, account, funds=1000000, *fake_receipts):
# type: (str, int, *str) -> None
"""Embezzle funds from account using fake receipts."""
<code goes here> Source: https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code
It would require another hack: from typing_extensions import NamedTuple
X = NamedTuple('X', [('a', int), ('b', str)]) However, I am not sure
This is very personal, because for me - type hinting is a massive reability boost. |
Mmm. If we stick with option 3), do
It doesn't matter (I will remove 2.6 eventually). Personally I wouldn't mind if typing support would be 3.X only... if that means the end result is better / cleaner / more maintainable etc. The only real constraint that we have is avoid breaking 2.7 code (that's gonna stay for many years to come). |
Also, another thing to consider is testing. Right now we have unit tests that check return types of all public APIs, including namedtuple values: |
We can store them separately in
Nope.
It will be just three extra files:
I don't think so. At least, I don't know how to do that. |
Sounds good. If you want to go for it, feel free to make a PR. |
I will! |
Summary
Description
Previously the wording was quite confusing:
name
is not afunction
(in a CPython's sense, likeCallable[...]
) and never used like one.I've changed the wording to be just
key
, whichname
is. Maybe there are better ways to describe it?Context: we are working on type stubs for
psutil
and found this description quite confusing python/typeshed#6104 (comment)