question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace typing.List with list and others

See original GitHub issue

https://docs.python.org/3.9/whatsnew/3.9.html#pep-585-builtin-generic-types

Python 3.9 (and Python 3.7 if you do from __future__ import annotations) will let you write

from typing import List

def a(my_arg: List) -> List:
    return []

as

def a(my_arg: list) -> list:
    return []

Same goes for typing.Dict and a bunch of others, see https://www.python.org/dev/peps/pep-0585/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jdufresnecommented, Dec 24, 2020

Perhaps another example of the same idea, replace typing.Text with str for --py3-plus.

Example input:

if False:
    from typing import Text


def f():
    # type: () -> Text
    return "hello"

Example diff:

--- before.py
+++ after.py
@@ -3,5 +3,5 @@
 
 
 def f():
-    # type: () -> Text
+    # type: () -> str
     return "hello"

1reaction
asottilecommented, Jan 22, 2021

via #371

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Using List/Tuple/etc. from typing vs directly referring ...
For typing.List and other sequence types you generally only specify the type for all elements; List[str] is a list of strings, of any...
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. The most fundamental support consists of the types Any, Union, Callable, ...
Read more >
Find and replace text - Microsoft Support
Go to Home > Replace. Enter the word or phrase you want to replace in Find what. Enter your new text in Replace...
Read more >
Type hints cheat sheet - mypy 0.991 documentation
(1, 2, 3) from typing import Union, Optional # On Python 3.10+, use the | operator when something could be one of a...
Read more >
3. Strings, lists, and tuples — Beginning Python Programming ...
If we want to modify a list and also keep a copy of the original, we need to be able to make a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found