Skip to content
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

Update test cases to work on 3.11 #178

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Conversation

hillary-mutisya
Copy link
Contributor

  • use the pre-3.11 approach for declaring generic classes and typealiastype
  • check for both typing.TypedDict and typing_extensions.TypedDict in _KNOWN_SPECIAL_BASES

T = TypeVar("T", covariant=True)


class First(Generic[T], TypedDict):
Copy link
Member

Choose a reason for hiding this comment

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

Currently TypeChat only understands generics using 3.12 syntax. It doesn't consider types that extend Generic[...] or generic protocols as adding type parameters. So I think we either find a way to make some of these tests only run in 3.12, or temporarily disable them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the TypeChat code to read type parameters for the classes that extend Generic[...] from the parameters field. With this, the generic_alias_1.py test now outputs type info correctly:

// Entry point is: 'FirstOrSecond'
// TypeScript Schema:

type FirstOrSecond<T> = First<T> | Second<T>

interface Second<T> {
    kind: "second";
    "second_attr": T;
}

interface First<T> {
    kind: "first";
    "first_attr": T;
}

Copy link
Contributor

@pcdeadeasy pcdeadeasy left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Contributor Author

@hillary-mutisya hillary-mutisya left a comment

Choose a reason for hiding this comment

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

Updated based on PR feedback

@DanielRosenwasser DanielRosenwasser merged commit 9b92a5c into main Feb 20, 2024
4 checks passed
@DanielRosenwasser DanielRosenwasser deleted the users/hillarym/tests_3.11 branch February 20, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants