Function dunders definition #3032
-
|
Where do function dunder type definitions come from? Examples being, def foo(x: int) -> bool:
...
foo.__annotations__
foo.__signature__
foo.__code__
...I'm unsure if there's a pyright bug or a typeshed bug as
makes me unsure if that's a mypy specific stub or if other type checkers use it. Broader question are there any special builtin types that don't have stubs in typeshed? Or should I expect all of them to be in builtins.pyi? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's unfortunately not a single answer to this question. It depends on which dunders you're talking about. Pyright tends to use definitions from typeshed wherever possible. For example, for functions (as in your example above), it uses the dunders from the |
Beta Was this translation helpful? Give feedback.
There's unfortunately not a single answer to this question. It depends on which dunders you're talking about. Pyright tends to use definitions from typeshed wherever possible. For example, for functions (as in your example above), it uses the dunders from the
functionclass inbuiltins.pyi. For modules, classes and functions, pyright's binder implicitly adds certain dunder symbols that are documented to exist but are not declared in typeshed stubs. You can find these by searching for_addImplicitSymbolToCurrentScopeinbinder.ts. Here's a link.