Questions tagged [python-3.5]

The version of the Python programming language released on September 13, 2015. For issues that are specific to Python 3.5. Use the more generic [python] and [python-3.x] tags where possible.

Python 3.5 was released on September 13, 2015 (PEP 478).


Use this tag if your question is specifically related to Python 3.5. Otherwise, use the following guidelines to determine which tag(s) you should add to your question:

  • If your question applies to Python in general, use only the tag.
  • If your question applies to Python 3.x but not to Python 2.x, add the tag .
  • If you aren't sure, tag your question with and mention which version you're using in the post.
3451 questions
660
votes
6 answers

How do I type hint a method with the type of the enclosing class?

I have the following code in python 3: class Position: def __init__(self, x: int, y: int): self.x = x self.y = y def __add__(self, other: Position) -> Position: return Position(self.x + other.x, self.y +…
Michael van Gerwen
  • 6,731
  • 3
  • 9
  • 8
341
votes
4 answers

How to specify multiple return types using type-hints

I have a function in python that can either return a bool or a list. Is there a way to specify the return types using type hints. For example, Is this the correct way to do it? def foo(id) -> list or bool: ...
Yahya Uddin
  • 18,489
  • 26
  • 104
  • 189
296
votes
5 answers

What are type hints in Python 3.5?

One of the most talked-about features in Python 3.5 is type hints. An example of type hints is mentioned in this article and this one while also mentioning to use type hints responsibly. Can someone explain more about them and when they should be…
Vaulstein
  • 15,782
  • 6
  • 40
  • 57
236
votes
1 answer

How to specify "nullable" return type with type hints

Suppose I have a function: def get_some_date(some_argument: int=None) -> %datetime_or_None%: if some_argument is not None and some_argument == 1: return datetime.utcnow() else: return None How do I specify the return type…
exfizik
  • 3,601
  • 4
  • 20
  • 26
217
votes
3 answers

How can I specify the function type in my type hints?

I want to use type hints in my current Python 3.5 project. My function should receive a function as parameter. How can I specify the type function in my type hints? import typing def my_function(name:typing.AnyStr, func: typing.Function) -> None: …
Jon
  • 7,706
  • 5
  • 33
  • 70
207
votes
11 answers

ImportError: No module named 'django.core.urlresolvers'

I am working on Django project where I need to create a form for inputs. I tried to import reverse from django.core.urlresolvers. I got an error: line 2, in from django.core.urlresolvers import reverse ImportError: No module named…
viratayya salimath
  • 2,275
  • 2
  • 6
  • 11
191
votes
3 answers

What is the '@=' symbol for in Python?

I know @ is for decorators, but what is @= for in Python? Is it just reservation for some future idea? This is just one of my many questions while reading tokenizer.py.
171
votes
6 answers

Python type hinting without cyclic imports

I'm trying to split my huge class into two; well, basically into the "main" class and a mixin with additional functions, like so: main.py file: import mymixin.py class Main(object, MyMixin): def func1(self, xxx): ... mymixin.py…
velis
  • 6,104
  • 4
  • 40
  • 50
164
votes
3 answers

Why is x**4.0 faster than x**4 in Python 3?

Why is x**4.0 faster than x**4? I am using CPython 3.5.2. $ python -m timeit "for x in range(100):" " x**4.0" 10000 loops, best of 3: 24.2 usec per loop $ python -m timeit "for x in range(100):" " x**4" 10000 loops, best of 3: 30.6 usec per…
arieljannai
  • 1,999
  • 3
  • 17
  • 34
154
votes
1 answer

How to annotate types of multiple return values?

How do I use type hints to annotate a function that returns an Iterable that always yields two values: a bool and a str? The hint Tuple[bool, str] is close, except that it limits the return value type to a tuple, not a generator or other type of…
Richard Hansen
  • 44,218
  • 20
  • 84
  • 95
144
votes
6 answers

Difference between numpy dot() and Python 3.5+ matrix multiplication @

I recently moved to Python 3.5 and noticed the new matrix multiplication operator (@) sometimes behaves differently from the numpy dot operator. In example, for 3d arrays: import numpy as np a = np.random.rand(8,13,13) b = np.random.rand(8,13,13) c…
blaz
  • 3,316
  • 5
  • 24
  • 48
142
votes
4 answers

"Fire and forget" python async/await

Sometimes there is some non-critical asynchronous operation that needs to happen but I don't want to wait for it to complete. In Tornado's coroutine implementation you can "fire & forget" an asynchronous function by simply ommitting the yield…
Mike N
  • 4,877
  • 3
  • 21
  • 19
116
votes
1 answer

Why is str.translate much faster in Python 3.5 compared to Python 3.4?

I was trying to remove unwanted characters from a given string using text.translate() in Python 3.4. The minimal code is: import sys s = 'abcde12345@#@$#%$' mapper = dict.fromkeys(i for i in range(sys.maxunicode) if chr(i) in…
Bhargav Rao
  • 41,091
  • 27
  • 112
  • 129
108
votes
4 answers

asyncio.ensure_future vs. BaseEventLoop.create_task vs. simple coroutine?

I've seen several basic Python 3.5 tutorials on asyncio doing the same operation in various flavours. In this code: import asyncio async def doit(i): print("Start %d" % i) await asyncio.sleep(3) print("End %d" % i) return i if…
crusaderky
  • 2,131
  • 2
  • 15
  • 24
93
votes
5 answers

Type hinting / annotation (PEP 484) for numpy.ndarray

Has anyone implemented type hinting for the specific numpy.ndarray class? Right now, I'm using typing.Any, but it would be nice to have something more specific. For instance if the NumPy people added a type alias for their array_like object class.…
Inon
  • 1,108
  • 2
  • 8
  • 17
1
2 3
99 100