Questions tagged [pep585]

4 questions
18
votes
1 answer

Is PEP 585 unusable at runtime under Python 3.7 and 3.8?

PEP 585 -- Type Hinting Generics In Standard Collections claims usability under both Python 3.7 and 3.8 with a standard from __future__ import annotations preamble. Notably: For use cases restricted to type annotations, Python files with the…
Cecil Curry
  • 9,789
  • 5
  • 38
  • 52
3
votes
0 answers

Linting to enforce PEP-585

I'd like to be able to run some linting that fails if my code uses from typing import List x: List[str] instead of x: list[str] for example. I currently use mypy, so ideally there'd be some way to achieve this with that.
UtterlyConfused
  • 983
  • 1
  • 10
  • 18
1
vote
0 answers

Raising DeprecationWarning in mypy for PEP 585

In a project I'm working on we're extensively using type hinting. And we're now updating to python 3.9, with it's expanded type hinting functionality defined in PEP 585. And testing the change I ran into an interesting issue. PEP 585…
thevoiddancer
  • 385
  • 2
  • 9
0
votes
1 answer

Python type hints: `def f(e: Union[np, tf])` for `import numpy as np`?

Goal: restrict function argument to only accept the numpy or tensorflow module. Some ideas I have, use Literal types (PEP586): Literal["np", "tf"] Then use globals() to find the symbol. This would work reasonably well, though obviously skips the…
A T
  • 13,008
  • 21
  • 97
  • 158