DEV Community

Discussion on: A Failed Experiment with Python Type Annotations

Collapse
 
evanoman profile image
Evan Oman • Edited

Adding on to @victorosilva 's comment, the annotation import is only available on Python 3.7+. For Python 3.6 and below, the workaround to the self-referential issue is to put the class name in single quotes, as discussed here:

class Position:
    ...
    def __add__(self, other: 'Position') -> 'Position':
       ...
Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Oh, I guess I'll try this approach first, since Ubuntu is on Python 3.6.8.

Collapse
 
evanoman profile image
Evan Oman

I also highly recommend conda environments, it is really nice to have per-project Python version and dependency specifications without messing with system Python.

Thread Thread
 
miniscruff profile image
miniscruff

Python has venv so you can just run python -m venv {path}.