No name ‘QApplication’ in module ‘PyQt5.QtWidgets’ error in Pylint

I’ve figured out the issue, apparently Pylint doesn’t load any C extensions by default, because those can run arbitrary code. So I found that if you create a system file in your project directory with the file named .pylintrc the rc file can whitelist this package to stop throwing errors by adding the following code … Read more

How can I launch ipython from shell, by running ‘python …’?

To start IPython shell directly in Python: from IPython import embed a = “I will be accessible in IPython shell!” embed() Or, to simply run it from command line: $ python -c “from IPython import embed; embed()” embed will use all local variables inside shell. If you want to provide custom locals (variables accessible in … Read more

aiogevent event loop “fails” to track greenlets

Taking a guess at this, but I think you’re using the event loop wrong for asyncio. I don’t know enough about gevent to understand what type of object it’s creating to know if this will work. The documentation would indicate that the order in which stop() and run_forever() are called is relevant to the operational … Read more

mypy “is not valid as a type” for types constructed with `type()`

How about this, as a workaround? from typing import Optional, TYPE_CHECKING if TYPE_CHECKING: class Foo: pass else: Foo = type(‘Foo’, (), {}) Bar = Optional[Foo] typing.TYPE_CHECKING is a constant that will always be True at compile-time, and will always be False at runtime. In this way, we can keep MyPy happy by only telling it … Read more

Static typing in python3: list vs List [duplicate]

Not all lists are the same from a typing perspective. The program def f(some_list: list): return [i+2 for i in some_list] f([‘a’, ‘b’, ‘c’]) won’t fail a static type checker, even though it won’t run. By contrast, you can specify the contents of the list using the abstract types from typing def f(some_list: List[int]) -> … Read more

Python: Usable Max and Min values

For numerical comparisons, +- float(“inf”) should work. It doesn’t always work (but covers the realistic cases): print(list(sorted([float(“nan”), float(“inf”), float(“-inf”), float(“nan”), float(“nan”)]))) # NaNs sort above and below +-Inf # However, sorting a container with NaNs makes little sense, so not a real issue. To have objects that compare as higher or lower to any other … Read more

Why can’t I sort a list of dicts in 3.x? Why do I get “TypeError: ‘

Python 2’s dictionary sort order was quite involved and poorly understood. It only happened to work because Python 2 tried to make everything orderable. For your specific case, with {‘name’: …} dictionaries with a single key, the ordering was determined by the value for that single key. In Python 3, where dictionaries are no longer … Read more