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

Reduce code duplication in the email module #7558

Merged
merged 4 commits into from
Apr 6, 2022
Merged

Conversation

AlexWaygood
Copy link
Member

2 type aliases and one TypeVar have duplicate definitions in several email submodules. I think it makes sense to move these definitions to a submodule in _typeshed instead, to reduce code duplicaiton.

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood changed the title Reduce code duplication by adding _typeshed.email.pyi Reduce code duplication by adding _typeshed/email.pyi Mar 27, 2022
@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Mar 30, 2022

Sorry for the late reply, but do we need this in _typeshed? Wouldn't it make more sense to have those aliases in one of the email modules and import from there?

@AlexWaygood
Copy link
Member Author

Sorry for the late reply

No worries — no rush!

but do we need this in _typeshed? Wouldn't it make more sense to have those aliases in one of the email modules and import from there?

Sure — though if we do that, we'll probably have to give them names with a leading underscore, and it feels a bit weird to import names with a leading underscore from other modules.

I also thought that we already did something similar with _typeshed.xml and _typeshed.wsgi — but perhaps I just misunderstood the purpose of those submodules :)

@srittau
Copy link
Collaborator

srittau commented Mar 30, 2022

At least the aliases and protocols in .wsgi are mainly intended for external use, while the aliases here are more for internal use, if I understand correctly?

@AlexWaygood
Copy link
Member Author

the aliases here are more for internal use, if I understand correctly?

Yes.

@srittau
Copy link
Collaborator

srittau commented Mar 30, 2022

To me, _typeshed is mainly intended for types that are also useful for typeshed users, or at least for types that are used by multiple parts of typeshed, while module-specific types should stay close to where they are used. But I'd be interested in what the general opinion on that is.

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Mar 31, 2022

What do we think about perhaps adding a fictitious submodule to the email package (_aliases.pyi? _typing.pyi?) that, like _typeshed, doesn't exist at runtime?

@AlexWaygood
Copy link
Member Author

What do we think about perhaps adding a fictitious submodule to the email package (_aliases.pyi? _typing.pyi?) that, like _typeshed, doesn't exist at runtime?

There appears to be little enthusiasm for this idea. I'll move the aliases to email.__init__ :)

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood requested a review from srittau April 3, 2022 21:37
@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 2022

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

@AlexWaygood AlexWaygood changed the title Reduce code duplication by adding _typeshed/email.pyi Reduce code duplication in the email module Apr 4, 2022
@srittau srittau merged commit 3c85f36 into python:master Apr 6, 2022
@AlexWaygood AlexWaygood deleted the email branch April 6, 2022 10:20
@AlexWaygood
Copy link
Member Author

Thanks @srittau!

@srittau
Copy link
Collaborator

srittau commented Apr 6, 2022

What do we think about perhaps adding a fictitious submodule to the email package (_aliases.pyi? _typing.pyi?) that, like _typeshed, doesn't exist at runtime?

Sorry for not answering earlier: _typeshed.wsgi used to be wsgiref._types, so there is precedent for that. But I prefer not to have "fake" modules, although I don't have a good justification for that, it's just a gut feeling.

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.

2 participants