GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-102721: Improve coverage of `_collections_abc._CallableGenericAlias` by sobolevn · Pull Request #102722 · python/cpython

Conversation

@sobolevn

@sobolevn sobolevn commented Mar 15, 2023 •
edited by AlexWaygood
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Two main changes:

  1. More pickle tests with different callables
  2. Passing things like 0 is not allowed, so I think testing this behaviour won't hurt. The test is quite simple

All tests work for both typing.Callable and _collections_abc.Callable.

I also went ahead and remove this suspicious if from #102681 (comment)

Moreover, all tests pass without it.
I cannot find any examples where it is needed. Please, prove me wrong.

CC @AlexWaygood

  • Issue: Improve coverage of _collections_abc._CallableGenericAlias #102721

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sobolevn
pythongh-102721: Improve coverage of `_collections_abc._CallableGener…
8ed3dd8
…icAlias`
@sobolevn
sobolevn requested review from AlexWaygood, Fidget-Spinner, JelleZijlstra, gvanrossum and rhettinger as code owners March 15, 2023 10:26
@bedevere-bot bedevere-bot mentioned this pull request Mar 15, 2023
Improve coverage of _collections_abc._CallableGenericAlias #102721
Closed
@bedevere-bot bedevere-bot added the awaiting review label Mar 15, 2023
@sobolevn sobolevn added the skip news label Mar 15, 2023
AlexWaygood
AlexWaygood reviewed Mar 15, 2023
View reviewed changes
Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn @AlexWaygood
Apply suggestions from code review
afe8f37
Co-authored-by: Alex Waygood <[email protected]>
AlexWaygood
AlexWaygood reviewed Mar 15, 2023
View reviewed changes
Comment thread Lib/_collections_abc.py
Comment on lines -487 to -492
# A special case in PEP 612 where if X = Callable[P, int],
# then X[int, str] == X[[int, str]].
if (len(self.__parameters__) == 1
and _is_param_expr(self.__parameters__[0])
and item and not _is_param_expr(item[0])):
item = (item,)

@AlexWaygood AlexWaygood Mar 15, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This makes me slightly nervous, but I can't find any changes in behaviour from removing this code.

@Fidget-Spinner and @serhiy-storchaka, can either of you think of anything bad that could happen if we remove this code? The whole test suite passes with it removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sobolevn sobolevn Mar 15, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, me too. Let's wait for others to comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@gvanrossum gvanrossum Mar 16, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It makes me nervous too. In case you're looking for an example that triggers this path, here's one:

from typing import ParamSpec
P = ParamSpec("P")
from collections.abc import Callable
C = Callable[[P], int]
print(C[str])

However I agree that if I just comment this out, the output is the same. It's possible that @serhiy-storchaka fixed the issue in the C code (the super() method) -- the code here is from Aug 4th, 2021, while he touched _Py_subs_parameters on May 8th, 2022.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@AlexWaygood AlexWaygood Mar 16, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, I found examples that triggered this code path, but for all of the examples I found, I couldn't find any differences in behaviour with this code deleted (repr, __args__, __parameters__, equality)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gvanrossum gvanrossum Mar 16, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Someone could trace through the C code that gets called and see if it does the right thing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sobolevn sobolevn Mar 16, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks like _unpack_args C function which was added in May now handles this case: https://github.com/python/cpython/blame/2dc94634b50f0e5e207787e5ac1d56c68b22c3ae/Objects/genericaliasobject.c#L361

It unpacks nested tuples to a flat format, so - this code is not needed anymore.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AlexWaygood AlexWaygood Mar 16, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't suppose the pure-Python code could be useful for PyPy, could it? (Don't see how it could, just throwing that out there)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sobolevn sobolevn Mar 16, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sorry, the only other iterperter I worked on is RustPython.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
AlexWaygood
AlexWaygood approved these changes Mar 15, 2023
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me other than my nervousness about https://github.com/python/cpython/pull/102722/files#r1137196475

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Mar 15, 2023
@rhettinger
rhettinger removed their request for review March 15, 2023 15:30
AlexWaygood
AlexWaygood reviewed Mar 16, 2023
View reviewed changes
Comment thread Lib/_collections_abc.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum approved these changes Mar 16, 2023
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Don’t worry about PyPy.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@AlexWaygood
AlexWaygood merged commit fbe82fd into python:main Mar 16, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Mar 16, 2023
@AlexWaygood

AlexWaygood commented Mar 16, 2023

Copy link
Copy Markdown
Member

Thanks @sobolevn! I'd like to backport the coverage improvements, but not the code changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn

sobolevn commented Mar 16, 2023

Copy link
Copy Markdown
Member Author

I'd like to backport the coverage improvements, but not the code changes.

Do you want me to do that? Or do you want to do that yourself?

I am fine with both :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Mar 16, 2023

Copy link
Copy Markdown
Member

Would be great if you could take care of it, thanks!

sobolevn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn

sobolevn commented Mar 16, 2023

Copy link
Copy Markdown
Member Author

Scheduled for tomorrow then :)

AlexWaygood reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

carljm added a commit to carljm/cpython that referenced this pull request Mar 17, 2023
@carljm
Merge branch 'main' into inlinecomp2
1a8f4a0
* main: (34 commits)
  pythongh-102701: Fix overflow in dictobject.c (pythonGH-102750)
  pythonGH-78530: add support for generators in `asyncio.wait` (python#102761)
  Increase stack reserve size for Windows debug builds to avoid test crashes (pythonGH-102764)
  pythongh-102755: Add PyErr_DisplayException(exc) (python#102756)
  Fix outdated note about 'int' rounding or truncating (python#102736)
  pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (python#102760)
  pythongh-99726: Improves correctness of stat results for Windows, and uses faster API when available (pythonGH-102149)
  pythongh-102192: remove redundant exception fields from ssl module socket (python#102466)
  pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (python#102743)
  pythongh-102737: Un-ignore ceval.c in the CI globals check (pythongh-102745)
  pythonGH-102748: remove legacy support for generator based coroutines from `asyncio.iscoroutine` (python#102749)
  pythongh-102721: Improve coverage of `_collections_abc._CallableGenericAlias` (python#102722)
  pythonGH-102653: Make recipe docstring show the correct distribution (python#102742)
  Add comments to `{typing,_collections_abc}._type_repr` about each other (python#102752)
  pythongh-102594: PyErr_SetObject adds note to exception raised on normalization error (python#102675)
  pythongh-94440: Fix issue of ProcessPoolExecutor shutdown hanging (python#94468)
  pythonGH-100112:  avoid using iterable coroutines in asyncio internally (python#100128)
  pythongh-102690: Use Edge as fallback in webbrowser instead of IE (python#102691)
  pythongh-102660: Fix Refleaks in import.c (python#102744)
  pythongh-102738: remove from cases generator the code related to register instructions (python#102739)
  ...
This was referenced Mar 17, 2023
[3.11] gh-102721: Improve coverage of _collections_abc._CallableGenericAlias #102788
Merged
[3.10] gh-102721: Improve coverage of _collections_abc._CallableGenericAlias #102790
Merged
miss-islington pushed a commit that referenced this pull request Mar 17, 2023
@sobolevn
[3.11] gh-102721: Improve coverage of `_collections_abc._CallableGene…
045c8a1
…ricAlias` (GH-102788)

This is a backport of #102722 without the `typing.py` changes.

Automerge-Triggered-By: GH:AlexWaygood
miss-islington pushed a commit that referenced this pull request Mar 17, 2023
@sobolevn
[3.10] gh-102721: Improve coverage of `_collections_abc._CallableGene…
e732a85
…ricAlias` (GH-102790)

This is a manual backport of #102722 but without `typing.py` changes and without `TypeVarTuple` case, because it was added in 3.11

Automerge-Triggered-By: GH:AlexWaygood
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
@sobolevn @AlexWaygood @Fidget-Spinner
pythongh-102721: Improve coverage of `_collections_abc._CallableGener…
dd97b75
…icAlias` (python#102722)

Co-authored-by: Alex Waygood <[email protected]>
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
@sobolevn @AlexWaygood @warsaw
pythongh-102721: Improve coverage of `_collections_abc._CallableGener…
c1672d3
…icAlias` (python#102722)

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AlexWaygood AlexWaygood AlexWaygood approved these changes
@gvanrossum gvanrossum gvanrossum approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner
@JelleZijlstra JelleZijlstra Awaiting requested review from JelleZijlstra JelleZijlstra is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@sobolevn @AlexWaygood @gvanrossum @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.