TYP: Remove Sequence[str] in type annotations
See original GitHub issueIn various places, we use Sequence[str]
as a type annotation. The problem is that a regular string also matches Sequence[str]
. So we need to look at the various places we use Sequence[str]
and change the type accordingly. Maybe just List
or ArrayLike
, dependent on the context.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:17 (17 by maintainers)
Top Results From Across the Web
Python 3 - type hints for sequences of str - Stack Overflow
You should use the Any Type if you are not sure from typing import Any def f(a: Sequence[Any], b: Sequence[Any]) -> List[Any]: return ......
Read more >Common issues and solutions - mypy 0.991 documentation
This section has examples of cases when you need to update your code to use static typing, and ideas for working around issues...
Read more >Python Type Checking (Guide) - Real Python
In this guide, you'll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit...
Read more >typing — Support for type hints — Python 3.11.1 documentation
Introducing syntax for annotating variables outside of function ... The deprecated types will be removed from the typing module in the first Python...
Read more >Using Python's Type Annotations - DEV Community
from typing import Sequence def print_names(names: Sequence[str]) ... from typing import List, Tuple # Declare a point type annotation using ...
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 FreeTop 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
Top GitHub Comments
Mostly it is this:
So we document a method like
DataFrame.to_string()
withcolumns
andheader
being a list of columns/names, and type it asSequence[str]
, but you can’t just pass a single string (it would match for typing). What we want to accept there is something array-like, but not a plain string.For
pandas-stubs
, I’m taking out all references toSequence[str]
and replacing it withList[str]
. Maybe that will be too narrow, but if someone has an argumentx
for some method that is a sequence and not a list, they could just dolist(x)
and the type checker will be happy.I think the debate here is more about what we do internally in the code. For the PR’s I submitted, narrowing the type to
List[str]
still passes themypy
type checking.The other issue is more of a documentation one, where we are not necessarily precise in the meanings of
list-like
,array-like
. I think that many times where we write in the docsarray-like
, we mean1-D array-like
, as we wouldn’t accept a higher dimensional array for those arguments.