Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

jwodder
Copy link
Contributor

@jwodder jwodder commented May 28, 2021

Closes #5546.

@srittau
Copy link
Collaborator

srittau commented May 28, 2021

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

@github-actions
Copy link
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
Member

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

@Akuli
Copy link
Collaborator

Akuli commented May 29, 2021

#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
Copy link
Collaborator

hauntsaninja commented May 30, 2021

+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
Copy link
Collaborator

srittau commented Jun 8, 2021

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