-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Implement PEP 560: Core support for typing module and generic types #76407
Comments
As discussed before, there will be two PRs. One for the core components, and the second one (large) for typing updates. I will open the first PR shortly. |
As for __class_getitem__, why not implement type.__getitem__ instead of hacking PyObject_GetItem()? |
For reference: PEP-560. |
This question was raised by Mark Shannon on python-dev. Actually, my initial implementation did exactly this, but I didn't like it for two reasons:
Mark however disappeared since then, so I don't know what is his current opinion. I am however not as sure about this now. If there are some arguments for this, then I can revert to the older approach (implementing |
Guido, what is your preference for the implementation of |
I like the current approach (PyObject_GetItem). I agree with both of your reasons to prefer it. |
This adds an overhead to every indexing. $ ./python -m perf timeit --compare-to=./python0 -s 'a = [1]' --duplicate=10000 'a[0]'
python0: ..................... 15.3 ns +- 0.5 ns
python: ..................... 16.1 ns +- 0.3 ns Mean +- std dev: [python0] 15.3 ns +- 0.5 ns -> [python] 16.1 ns +- 0.3 ns: 1.05x slower (+5%) $ ./python -m perf timeit --compare-to=./python0 -s 'd = {1: 2}' --duplicate=10000 'd[1]'
python0: ..................... 17.6 ns +- 0.6 ns
python: ..................... 18.4 ns +- 0.5 ns Mean +- std dev: [python0] 17.6 ns +- 0.6 ns -> [python] 18.4 ns +- 0.5 ns: 1.05x slower (+5%) |
I'm not doubting your results, but I'm curious how that happened. The extra |
I think this is a cause. The difference may be dependent on the compiler and platform. |
Interesting. I have noticed similar when I tried to add a fast loop proposed by Serhiy. It should save at least one pointer comparison for base class, but sometimes it actually led to slow-downs (although very small). How can one fight this kind of problems? |
I think the best thing to do is not to panic! Also maybe PGO could help? On Dec 14, 2017 15:43, "Ivan Levkivskyi" <report@bugs.python.org> wrote:
|
It is very to get stable benchmarks with timings shorter than 1 ms, and even harder for timings shorter than 1 us. I wrote documentation to implement how to get more stable results: On Linux, using CPU isolation helps a lot, and perf uses automatically isolated CPUs. |
Please don't forgot to document this feature. |
Can I help? I'm implementing the feature related to pickling classes, and want to implement pickling generic types as an example. But since PEP-560 will change all here, I need to wait this change. |
Serhiy, I am sorry for a delay, I have recently moved to another country, this is why I have not much time. I will try to work on this weekend. Here are some points where you can be helpful:
(I know this might be not very interesting, but this will save time for me to focus only on typing part.) |
Sorry, I know very small about this module to writing the documentation. |
Since the commit 45700fb, test_genericclass leaks references: 1 test failed: Total duration: 107 ms The leak comes from _testcapi.Generic[int]. Maybe from generic_alias_new() of Modules/_testcapi.c. |
Oh ok, I think that I found the bug: PR 5212. |
What's the status of this? The issue is still open with "release blocker" status. |
I think all the critical things have been implemented/fixed. There are unfortunately no docs yet (my fault), also there are two bugs related to PEP-560, but they are not new, they also exist in Python 3.6. I am however marking this as high priority, since these two bugs prevent progress on other projects (pickling generic classes), so it would be good to fix them before beta-2. |
Are there more specific descriptions of those bugs? Links to a tracker? |
python/typing#512 and python/typing#511 are first issue (they are closely related to each other). This is not directly related to PEP-560, but changes in typing because of it will allow to fix them in a simple manner. The second one is Union simplification (was discussed in few PRs on typing tracker). This is not really a bug, but something we should decide on before 3.7 final. It will be difficult to change it later. Again, with PEP-560 in place the corresponding refactoring for removal should be straightforward. In addition, there is python/typing#392, this is already almost fixed by the typing PR implementing PEP-560, but it doesn't work for dunder attributes (I think we should not relay only specific set of reserved names, rather than all dunders). |
ISTM that those ought to be separate issues since PEP-560 has been Also I am getting cold feet about Union simplification (esp. this late in |
OK, I will close this issue, and open separate issues for documentation, Union, etc. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: