question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Full type hinting

See original GitHub issue

Summary

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.

image

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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
crazygmr101commented, Jun 3, 2021

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.

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 😛

0reactions
NCPlayzcommented, Jun 3, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found