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

Stubs and use of @deprecated names #18007

Open
JelleZijlstra opened this issue Oct 21, 2024 · 7 comments
Open

Stubs and use of @deprecated names #18007

JelleZijlstra opened this issue Oct 21, 2024 · 7 comments
Labels
bug mypy got something wrong topic-pep-702 PEP 702, @deprecated topic-stubtest

Comments

@JelleZijlstra
Copy link
Member

Running stubtest from mypy main on typeshed produces:

error: not checking stubs due to mypy build errors:
stdlib/asyncio/events.pyi:23: note: class asyncio.unix_events.AbstractChildWatcher is deprecated: Deprecated as of Python 3.12; will be removed in Python 3.14  [deprecated]
stdlib/unittest/__init__.pyi:53: note: function unittest.loader.findTestCases is deprecated: Deprecated in Python 3.11; removal scheduled for Python 3.13  [deprecated]
stdlib/unittest/__init__.pyi:53: note: function unittest.loader.getTestCaseNames is deprecated: Deprecated in Python 3.11; removal scheduled for Python 3.13  [deprecated]
stdlib/unittest/__init__.pyi:53: note: function unittest.loader.makeSuite is deprecated: Deprecated in Python 3.11; removal scheduled for Python 3.13  [deprecated]

Which is not very useful. Maybe we should suppress deprecated in typeshed's configuration or in stubtest in general.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-pep-702 PEP 702, @deprecated labels Oct 21, 2024
@JelleZijlstra
Copy link
Member Author

(I added a topic-pep-702 label, @tyralla fyi.)

@hauntsaninja
Copy link
Collaborator

I think suppressing all deprecated errors in stubs could make sense

@JelleZijlstra
Copy link
Member Author

I feel that might be too much; if we deprecate something in _typeshed, we'd want mypy to tell stub authors about it.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 22, 2024

We could just special case typeshed stubs in particular then (mypy already does this in a few places)

(And in general that feels niche / for type-only programs removals don't feel too much more disruptive than deprecations)

@tyralla
Copy link
Collaborator

tyralla commented Oct 22, 2024

Do you mean just extending the current warn_deprecated method like this?

    def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:
        """Warn if deprecated."""
        if isinstance(node, Decorator):
            node = node.func
        if isinstance(node, (FuncDef, OverloadedFuncDef, TypeInfo)) and (
            (deprecated := node.deprecated) is not None
        ) and not self.is_typeshed_stub:  # !!!
            warn = self.msg.fail if self.options.report_deprecated_as_error else self.msg.note
            warn(deprecated, context, code=codes.DEPRECATED)

If so (and if it works, not checked so far), I could modify PR #17926 accordingly, which still suffers under typeshed issues.

(Thanks for the new label, @JelleZijlstra.)

@hauntsaninja
Copy link
Collaborator

Yup!

@tyralla
Copy link
Collaborator

tyralla commented Oct 22, 2024

Seems I am starting to learn some Mypy slang ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-pep-702 PEP 702, @deprecated topic-stubtest
Projects
None yet
Development

No branches or pull requests

4 participants