Skip to content

Set return type of Match.__getitem__ to Optional[AnyStr] - #5547

Closed
jwodder wants to merge 1 commit into
python:masterfrom
jwodder:gh-5546
Closed

jwodder wants to merge 1 commit into
python:masterfrom
jwodder:gh-5546

Conversation

@jwodder

@jwodder jwodder commented May 28, 2021

Copy link
Copy Markdown
Contributor

Closes #5546.

@srittau

srittau commented May 28, 2021

Copy link
Copy Markdown
Collaborator

This probably has the same problems as outlined in #3902, although the primer run will be interesting.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

freqtrade (https://github.com/freqtrade/freqtrade.git)
+ freqtrade/data/history/jsondatahandler.py:34: error: Item "None" of "Optional[str]" has no attribute "replace"
+ freqtrade/data/history/jsondatahandler.py:34: error: List comprehension has incompatible type List[Tuple[Union[str, Any], Optional[str]]]; expected List[Tuple[str, str]]
+ freqtrade/data/history/jsondatahandler.py:50: error: Item "None" of "Optional[str]" has no attribute "replace"
+ freqtrade/data/history/jsondatahandler.py:135: error: Item "None" of "Optional[str]" has no attribute "replace"
+ freqtrade/data/history/hdf5datahandler.py:33: error: Item "None" of "Optional[str]" has no attribute "replace"
+ freqtrade/data/history/hdf5datahandler.py:33: error: List comprehension has incompatible type List[Tuple[Union[str, Any], Optional[str]]]; expected List[Tuple[str, str]]
+ freqtrade/data/history/hdf5datahandler.py:49: error: Item "None" of "Optional[str]" has no attribute "replace"
+ freqtrade/data/history/hdf5datahandler.py:134: error: Item "None" of "Optional[str]" has no attribute "replace"

paroxython (https://github.com/laowantong/paroxython.git)
+ paroxython/flatten_ast.py:506: error: Item "None" of "Optional[Any]" has no attribute "startswith"
+ paroxython/flatten_ast.py:510: error: Item "None" of "Optional[Any]" has no attribute "startswith"
+ paroxython/flatten_ast.py:542: error: Argument 1 to "int" has incompatible type "Optional[Any]"; expected "Union[str, bytes, SupportsInt, SupportsIndex, _SupportsTrunc]"

@JelleZijlstra

Copy link
Copy Markdown
Member

Interesting, the primer output is less bad than I'd expect.

@Akuli

Akuli commented May 29, 2021

Copy link
Copy Markdown
Collaborator

#5528 is similar. I think we should make all the grouping methods (at least group, groups, __getitem__) consistent with each other, instead of fixing them one by one in one-line pull requests.

@hauntsaninja

hauntsaninja commented May 30, 2021 •

Copy link
Copy Markdown
Collaborator

+1 to Akuli's point. To the extent that we trust mypy primer, it'll also let us see the damage in a single PR. I also do seem to recall us having made changes along these lines and having to revert them based on Dropbox's experience.
FWIW, I think I'm probably in the "just return Any" camp.

@srittau

srittau commented Jun 8, 2021

Copy link
Copy Markdown
Collaborator

Superseded by #5557. Thank you for the PR, this was quite useful for figuring out the best way forward.

@srittau srittau closed this Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect annotation for Match.__getitem__

5 participants