Self-reference or forward-reference of type annotations in Python [duplicate]

PEP 0484 – Type Hints – The problem of forward declarations addresses the issue: The problem with type hints is that annotations (per PEP 3107 , and similar to default values) are evaluated at the time a function is defined, and thus any names used in an annotation must be already defined when the function … Read more

Dict merge in a dict comprehension

It’s not exactly an answer to your question but I’d consider using ChainMap to be an idiomatic and elegant way to do what you propose (merging dictionaries in-line): >>> from collections import ChainMap >>> d1 = {1: ‘one’, 2: ‘two’} >>> d2 = {3: ‘three’} >>> ds = [d1, d2] >>> dict(ChainMap(*ds)) {1: ‘one’, 2: … Read more

How to iterate through a list of dictionaries

You could just iterate over the indices of the range of the len of your list: dataList = [{‘a’: 1}, {‘b’: 3}, {‘c’: 5}] for index in range(len(dataList)): for key in dataList[index]: print(dataList[index][key]) or you could use a while loop with an index counter: dataList = [{‘a’: 1}, {‘b’: 3}, {‘c’: 5}] index = 0 … Read more

How do I specify OrderedDict K,V types for Mypy type annotation?

There is no problem in mypy (at least, not in 0.501). But there is a problem with Python 3.6.0. Consider the following: from collections import OrderedDict from typing import Dict def foo() -> Dict[str, int]: result: OrderedDict[str, int] = OrderedDict() result[‘two’] = 2 return result This code will both satisfy mypy (0.501) and Python (3.6.0). … Read more

@asyncio.coroutine vs async def

Yes, there are functional differences between native coroutines using async def syntax and generator-based coroutines using the asyncio.coroutine decorator. According to PEP 492, which introduces the async def syntax: Native coroutine objects do not implement __iter__ and __next__ methods. Therefore, they cannot be iterated over or passed to iter(), list(), tuple() and other built-ins. They … Read more

pip3 error – ‘_NamespacePath’ object has no attribute ‘sort’

I met the same issue with python 3.5.2 and pip3 (9.0.1). And I fixed it by following this workaround: https://github.com/pypa/setuptools/issues/885#issuecomment-307696027 More specifically, I edited line #2121~2122 of this file: “sudo vim /usr/local/lib/python3.5/dist-packages/pip/_vendor/pkg_resources/__init__.py” #orig_path.sort(key=position_in_sys_path) #module.__path__[:] = [_normalize_cached(p) for p in orig_path] orig_path_t = list(orig_path) orig_path_t.sort(key=position_in_sys_path) module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)