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.

I have started to use mypy. Aaaand it is not so good right now.

Libraries lack typing support. And I know that mimesis support only python3. Do you consider adding type hints?

There are some advantages:

  • stricter API
  • static analysis support to improve quality

There are some disadvantages:

  • type hinting was introduced in python3.5, so any version prior to that will have to use special comments or other hacks
  • a lot of manual work
  • possible API changes

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
lk-geimfaricommented, Nov 10, 2017

Sooo, it’s done!

1reaction
bjd2385commented, Oct 30, 2017

@lk-geimfari I’ve already mentioned this in #267, but if one is defaulting the argument to None, which is automatically pushed to type(None) or NoneType, then we should use typing.Optional[the_type]. In the example above, we’d have

def randints(self, amount: Optional[int] = None, a: int = 1, b: int = 100) -> list:
        """Generate list of random integers.

        :param amount: Amount of elements.
        :param a: Minimum value of range.
        :param b: Maximum value of range.
        :return: List of random integers.
        """

        if amount is None:
            amount = 3

        return [self.randint(a, b) for _ in range(amount)]

By the way, I believe I mistakenly reversed the logic of that predicate in my PR earlier 😛

Read more comments on GitHub >

github_iconTop Results From Across the Web

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
In this lesson, you'll learn about type hinting in Python. Type hinting is a formal solution to statically indicate the type of a...
Read more >
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 >
Type hinting in PyCharm - JetBrains
To add a type hint, follow these steps: · Select a code element. · Press Alt+Enter . · Select Add type hint for...
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