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 — Fix tests on Python 3.12 by JelleZijlstra · Pull Request #162 · python/typing_extensions

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented May 19, 2023

Copy link
Copy Markdown
Member

On current Python main, TypeVar cannot be subclassed. However, we still need to enhance TypeVar to add the default= argument. This PR introduces an alternative approach to achieve that: we create a dummy class that wraps typing.TypeVar and when instantiated, returns an instance of typing.TypeVar, possibly with some additional attributes. We also set __instancecheck__ so that isinstance(x, typing_extensions.TypeVar) continues to work.

Also fix a few other minor test failures on current CPython main.

Sorry, something went wrong.

Uh oh!

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

All reactions
JelleZijlstra added 4 commits May 19, 2023 08:39
@JelleZijlstra
Fix tests on Python 3.12
d96be43
@JelleZijlstra
More tests
f3ba193
@JelleZijlstra
don't need that
99d7c8c
@JelleZijlstra
if only we had Black
c4ee8c7
@JelleZijlstra
JelleZijlstra requested a review from AlexWaygood May 19, 2023 15:52
AlexWaygood
AlexWaygood reviewed May 19, 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.

The code looks good! A few comments about the tests. The only big concern I have is about typing.Unpack -- I think we should backport python/cpython#104048 rather than just fiddling with the test to make it pass on 3.12.

Feels like we could probably share more code between _TypeVarMeta, _ParamSpecMeta and _TypeVarTupleMeta, but that can definitely be tackled in a followup PR; no need to worry about it now.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/test_typing_extensions.py Resolved

Uh oh!

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

Comment thread src/test_typing_extensions.py Resolved

Uh oh!

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

Comment thread src/test_typing_extensions.py Resolved

Uh oh!

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

Comment thread src/typing_extensions.py
class TypeVar(metaclass=_TypeVarMeta):
"""Type variable."""

__module__ = 'typing'

@AlexWaygood AlexWaygood May 19, 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.

heh

Sorry, something went wrong.

Uh oh!

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

All reactions
@JelleZijlstra
Merge branch 'main' into 312
bca6f65
AlexWaygood
AlexWaygood reviewed May 19, 2023
View reviewed changes
Comment thread src/test_typing_extensions.py Resolved

Uh oh!

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

@JelleZijlstra JelleZijlstra mentioned this pull request May 20, 2023
PEP 695: typing.TypeVar should be subclassable python/cpython#104662
Closed
JelleZijlstra and others added 2 commits May 19, 2023 17:20
@JelleZijlstra
import textwrap
da4a52e
@JelleZijlstra @AlexWaygood
Update src/test_typing_extensions.py
abe9377
Co-authored-by: Alex Waygood <[email protected]>
@JelleZijlstra

JelleZijlstra commented May 20, 2023

Copy link
Copy Markdown
Member Author

Feels like we could probably share more code between _TypeVarMeta, _ParamSpecMeta and _TypeVarTupleMeta, but that can definitely be tackled in a followup PR; no need to worry about it now.

I'm not sure that's feasible. The code is similar for all three, but not quite the same: they all take different arguments and map to different typing classes.

All reactions

Sorry, something went wrong.

Uh oh!

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

@JelleZijlstra
JelleZijlstra requested a review from AlexWaygood May 20, 2023 00:23
AlexWaygood
AlexWaygood approved these changes May 20, 2023
View reviewed changes

@AlexWaygood AlexWaygood left a comment •
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.

The changes look good, and I confirmed that the tests all pass on CPython main.

It looks like the tests do currently crash on 3.12 alpha7, due to this not being valid syntax until very recently:

typing_extensions/src/test_typing_extensions.py

Lines 2404 to 2405 in 40dbc09

class Foo[T](Protocol):
def meth(self, x: T) -> None: ...

(See https://github.com/python/typing_extensions/actions/runs/5029362366/jobs/9020946297?pr=162)

So I suppose we could possibly make this sys.version_info check more fine-grained:

typing_extensions/src/test_typing_extensions.py

Line 2399 in 40dbc09

if sys.version_info >= (3, 12):

But also, the beta is about to be released, so maybe it doesn't matter too much?

Sorry, something went wrong.

Uh oh!

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

All reactions
@JelleZijlstra

JelleZijlstra commented May 20, 2023

Copy link
Copy Markdown
Member Author

Thanks! I'll push something to make it check for hasattr(typing, 'TypeAliasType') instead. I remember @carljm saying at the language summit that it's impossible to test any third-party libraries on early alphas; maybe we can make typing-extensions a partial exception :)

AlexWaygood and carljm reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

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

JelleZijlstra added 2 commits May 20, 2023 16:23
@JelleZijlstra
Fix previous alphas
665e2b7
@JelleZijlstra
Merge branch 'main' into 312
9153e12
@JelleZijlstra
JelleZijlstra merged commit 8b6582e into python:main May 20, 2023
@JelleZijlstra
JelleZijlstra deleted the 312 branch May 20, 2023 23:29
@AlexWaygood AlexWaygood mentioned this pull request May 21, 2023
Slightly cleanup implementation of typevarlikes #170
Merged
@blink1073 blink1073 mentioned this pull request May 25, 2023
Vendored typing-extensions is incompatible with Python 3.12 pypa/pip#12053
Closed
1 task done
@benclifford benclifford mentioned this pull request Jun 2, 2023
Fix decorator typing to wrap_errors using ParamSpec Parsl/parsl#2678
Merged
@deric4 deric4 mentioned this pull request Jun 16, 2023
macOS: universal package python3.12 crashes when running pip debug actions/setup-python#684
Closed
2 of 5 tasks
@charliermarsh charliermarsh mentioned this pull request Jun 16, 2023
Ruff server crash on VSC for python 3.12: TypeError: type 'typing.TypeVar' is not an acceptable base type astral-sh/ruff-vscode#200
Closed
@p1c2u p1c2u mentioned this pull request Jul 13, 2023
TypeError on Python 3.12b4 p1c2u/jsonschema-path#44
Closed
ghickman added a commit to opensafely-core/job-server that referenced this pull request Oct 9, 2023
@ghickman
Bump typing-extensions to 4.8.0
a55d9c1
This brings in a fix for python 3.12:

python/typing_extensions#162
@otaviojacobi otaviojacobi mentioned this pull request Oct 12, 2023
Python 3.12 compatability balena-io/balena-sdk-python#347
Closed
@benjamb benjamb mentioned this pull request Jun 2, 2024
Update 'typing_extensions' to >=4.6.0 to fix python 3.12 error python/mypy#17312
Merged
JelleZijlstra pushed a commit to python/mypy that referenced this pull request Jun 2, 2024
@benjamb
Update 'typing_extensions' to >=4.6.0 to fix python 3.12 error (#17312)
2116386
With earlier versions of typing_extensions, the following traceback is
seen:

```
Traceback (most recent call last):
  File ".../bin/mypy", line 5, in <module>
    from mypy.__main__ import console_entry
  File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module>
    from mypy.main import main, process_options
  File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module>
    from typing_extensions import Final
  File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module>
    class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
TypeError: type 'typing.TypeVar' is not an acceptable base type
```

The error is addressed in typing_extensions in
 python/typing_extensions#162, which is included
in the 4.6.0 release.
GiorgosPapoutsakis pushed a commit to GiorgosPapoutsakis/mypy that referenced this pull request Jun 3, 2024
@benjamb @GiorgosPapoutsakis
Update 'typing_extensions' to >=4.6.0 to fix python 3.12 error (pytho…
842e57b
…n#17312)

With earlier versions of typing_extensions, the following traceback is
seen:

```
Traceback (most recent call last):
  File ".../bin/mypy", line 5, in <module>
    from mypy.__main__ import console_entry
  File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module>
    from mypy.main import main, process_options
  File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module>
    from typing_extensions import Final
  File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module>
    class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
TypeError: type 'typing.TypeVar' is not an acceptable base type
```

The error is addressed in typing_extensions in
 python/typing_extensions#162, which is included
in the 4.6.0 release.
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

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

2 participants

@JelleZijlstra @AlexWaygood
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.