PEP 585 support in 3.7+ using __future__
See original GitHub issueDescribe the bug Vermin reports the minimum version is Python 3.9, even though the code will run correctly in Python 3.7+.
To Reproduce Steps to reproduce the behavior.
Run the following code in Python 3.7, 3.8, 3.9
from __future__ import annotations
def fn(x: list[int]) -> list[int]:
a: list[int] = []
return a
fn([])
Output:
Detecting python files..
Analyzing using 12 processes..
!2, 3.9 /Users/tyler.yep/Documents/Github/probs/yo.py
L1 C5: '__future__' module requires 2.1, 3.0
L1 C5: '__future__.annotations' member requires !2, 3.7
L4: annotations requires !2, 3.0
L4: builtin generic type annotation (list[..]) requires !2, 3.9
L5: variable annotations requires !2, 3.6
L5: builtin generic type annotation (list[..]) requires !2, 3.9
L6: builtin generic type annotation (list[..]) requires !2, 3.9
Minimum required versions: 3.9
Incompatible versions: 2
Expected behavior Minimum version should be Python 3.7
Environment:
- Vermin latest version (1.1.0)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Is PEP 585 unusable at runtime under Python 3.7 and 3.8?
For use cases restricted to type annotations, Python files with the annotations future-import (available since Python 3.7) can parameterize ...
Read more >PEP 585 – Type Hinting Generics In Standard Collections
This PEP proposes to enable support for the generics syntax in all ... Starting with Python 3.7, when from __future__ import annotations is ......
Read more >PEP 585 parameterized built-in classes are not recognized ...
Starting with Python 3.7, when from future import annotations is used, function and variable annotations can parameterize standard collections directly. Example ...
Read more >Annotation issues at runtime - mypy 0.991 documentation
Use of from __future__ import annotations (PEP 563) (this behaviour may ... There is limited support for using this syntax in Python 3.7...
Read more >Python Type Hints - How to Upgrade Syntax with pyupgrade
PEP 585 added generic syntax to builtin types. ... But we can use both syntaxes today, even from Python 3.7, with Mypy 0.800+...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I also discovered this earlier but didn’t have time to organize it and create an issue 😃 Just want to point out some important points to consider for implementation:
from __future__ import annotations) makes function and variable annotations stored in string form. They are not evaluated at definition time, but only evaluated when you manually calltyping.get_type_hintsoreval(obj.__annotations__). The following code snippet:is 3.7+, but this one:
is 3.9+. Probably there could be a command line option for users to inform
verminwhether the annotations in the code will be manually evaluated or not.is 3.6+ (since variable annotations are 3.6+), even if
from __future__ import annotationsis not present.is 3.7+, since
list[int]andint | strare valid syntax in Python 3.7. While this one:is still 3.8+.
int | strwere a 3.11 feature (instead of 3.10 in reality). The following codewill still be 3.10+ since the PEP 563 is always enabled (without having to write
from __future__ import annotations) in 3.10 andint | stris not new syntax.Thanks again, both. Will release version 1.1.1 soon.