Full type hinting
See original GitHub issueSummary
Typehinting everything in the library as per PEP 484
What is the feature request for?
The core library
The Problem
Pycharm’s inferred typehints don’t seem to work as well as they should due to the fact the library doesn’t use typehints are per PEP 484. It seems to be able to somewhat infer them from the ReST-style docs, but not fully. I’ve not seen this problem with typehints.
The particular line from the code
def add_listener(self, func, name=None):
"""The non decorator alternative to :meth:`.listen`.
Parameters
-----------
func: :ref:`coroutine <coroutine>`
The function to call.
name: Optional[:class:`str`]
The name of the event to listen for. Defaults to ``func.__name__``.
The Ideal Solution
If name
was typehinted as name: str = None
, pycharm would be able to infer it correctly.
The Current Solution
The current solution(s) to the problem would be ignoring the warnings, or disabling them entirely. While these are completely valid solutions, they seem suboptimal, especially when working with an undocumented version, i.e., 2.0.
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Type hints cheat sheet - mypy 0.991 documentation
Type hints cheat sheet#. This document is a quick cheat sheet showing how to use type annotations for various common types in Python....
Read more >Python Type Hints
In this tutorial, you'll learn about the python type hints and how to use the mypy tool to check types statically. ... Here...
Read more >typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar ......
Read more >Type Hinting - Real Python
Type hinting is a formal solution to statically indicate the type of a value within your Python code. It was specified in PEP...
Read more >Type Hints in Python - GeeksforGeeks
Type Hints in Python ... Python is a dynamically typed language, which means you never have to explicitly indicate what kind of variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m actually running a fork of 2.0, trying to keep up with Interactions and the latest changes. I’ve written a small library to handle buttons and such, but I know this lib would more than likely do it better 😛
While you could wait until 2.0 for full/official typings of the library, @BryanForbes has kindly been maintaining stubs for 1.x versions of the library, which can be seen here.