Skip to content

Conversation

@simonjayhawkins
Copy link
Member

pre-cursor to #41590

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label May 21, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone May 21, 2021
from __future__ import annotations

import codecs
from collections.abc import Callable # noqa: PDF001
Copy link
Member Author

@simonjayhawkins simonjayhawkins May 21, 2021

Choose a reason for hiding this comment

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

we should disable the custom pandas flake rule.

we should be importing Callable from collections.abc
https://docs.python.org/3/library/typing.html#callable

from typing import (
TYPE_CHECKING,
Hashable,
Pattern,
Copy link
Member Author

@simonjayhawkins simonjayhawkins May 21, 2021

Choose a reason for hiding this comment

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

we should not be using Pattern from typing.

https://www.python.org/dev/peps/pep-0585/

Importing those from typing is deprecated

if regex and (is_compiled_re or len(pat) > 1 or flags or callable(repl)):
if not is_compiled_re:
if regex and (
isinstance(pat, re.Pattern) or len(pat) > 1 or flags or callable(repl)
Copy link
Member Author

Choose a reason for hiding this comment

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

mypy cannot narrow types with is_compiled_re

raise ValueError("Cannot use a callable replacement when regex=False")

if case is None:
case = True
Copy link
Member Author

Choose a reason for hiding this comment

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

changed so that case is not optional on array methods. all validation is done here.


import abc
from typing import Pattern
from collections.abc import Callable # noqa: PDF001
Copy link
Member Author

Choose a reason for hiding this comment

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

another reason to disable the flake rule. abc is imported.

@jreback jreback merged commit 70d4697 into pandas-dev:master May 21, 2021
@jreback
Copy link
Contributor

jreback commented May 21, 2021

thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the typing-replace branch May 21, 2021 15:19
TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Typing type annotations, mypy/pyright type checking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants