Skip to content

Fix type annotation in pandas.compat #26252

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

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ follow_imports=silent
[mypy-pandas.conftest,pandas.tests.*]
ignore_errors=True

[mypy-pandas.compat]
ignore_errors=True

[mypy-pandas.core.api]
ignore_errors=True

Expand Down
10 changes: 2 additions & 8 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* platform checker
"""
import platform
import re
import struct
import sys
from typing import Pattern

PY36 = sys.version_info >= (3, 6)
PY37 = sys.version_info >= (3, 7)
Expand Down Expand Up @@ -74,13 +74,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):
raise exc.with_traceback(traceback)


# In Python 3.7, the private re._pattern_type is removed.
# Python 3.5+ have typing.re.Pattern
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these comments because they're misleading. typing.re.Pattern is available in 3.5-3.7. It's been removed from the documentation as of 3.6, but it continues to be available. As of 3.6, the documented method is to use typing.Pattern, which also works in 3.5. I've adopted that pattern in this PR, which corrected the mypy error

if PY36:
import typing
re_type = typing.re.Pattern
else:
re_type = type(re.compile(''))
re_type = Pattern


# https://github.com/pandas-dev/pandas/pull/9123
Expand Down