Skip to content

Conversation

@citruz
Copy link
Contributor

Description

This PR fixes#12072 by correctly handling Protocol definitions. Previously, the Protocol base class was removed when generating type stubs which causes problems with other packages that want to use type definition (because they see it as a regular class, not as a Protocol).

Test Plan

Added a testcase to the stubgen testset.

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

[case testProtocol_semanal]
from typing import Protocol

class P(Protocol):
Copy link
Member

Choose a reason for hiding this comment

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

Let's also add a generic Protocol[T] class here 🤔

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You mean like this?

T=TypeVar('T') classPT(Protocol[T]): deff(self, x: T) ->T: ...

That results in:

T=TypeVar('T') classPT(Protocol): deff(self, x: T) ->T: ...

So I guess that needs to be handled explicitly in my implementation?

Copy link
Member

Choose a reason for hiding this comment

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

Yes 🙂

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done ✅

@github-actions

This comment has been minimized.

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Thank you! 👍

@sobolevn
Copy link
Member

@srittau do you want to double check this? I've seen multiple your PRs to stubgen 🙂

@citruz
Copy link
ContributorAuthor

Any updates on this? :)

@JelleZijlstra
Copy link
Member

If you fix the merge conflict I can review it and hopefully merge it.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstraJelleZijlstra merged commit 21d957a into python:masterMar 18, 2022
@citruzcitruz deleted the fix-protocols branch March 18, 2022 06:50
Sign up for freeto 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.

stubgen removes Protocol from base classes list

5 participants

@citruz@sobolevn@JelleZijlstra@raghavthind2005@97littleleaf11