Skip to content

Remove obsolete mypy bug workaround in abspath() #12208

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 5 commits into from
Jun 25, 2024
Merged

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Jun 25, 2024

No description provided.

This comment has been minimized.

@AlexWaygood
Copy link
Member

Can we also get rid of the similar overloads in re.pyi? Or is that a different issue?

typeshed/stdlib/re.pyi

Lines 236 to 246 in c709686

# Type-wise the compile() overloads are unnecessary, they could also be modeled using
# unions in the parameter types. However mypy has a bug regarding TypeVar
# constraints (https://github.com/python/mypy/issues/11880),
# which limits us here because AnyStr is a constrained TypeVar.
# pattern arguments do *not* accept arbitrary buffers such as bytearray,
# because the pattern must be hashable.
@overload
def compile(pattern: AnyStr, flags: _FlagsType = 0) -> Pattern[AnyStr]: ...
@overload
def compile(pattern: Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: ...

This comment has been minimized.

@AlexWaygood
Copy link
Member

Okay it looks like weird things happen if you try to pass an object typed as Pattern[Any] for the re.pyi overloads (https://github.com/unionai-oss/pandera/blob/7420fc5de7b8b1b8bac31139ea95577ebf0a427c/pandera/api/checks.py#L432-L439), so maybe we should leave those for another PR and consider them separately. Sorry for the back-and-forth :(

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM. From the mypy_primer result when we tried to do similarly with the re.pyi overloads, I guess you might run into false positives if you tried to pass an object typed as PathLike[Any] into one of these functions. But I'd guess that's pretty rare. By far the most common PathLike object around is pathlib.Path, which is PathLike[str] rather than PathLike[Any].

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 271df8e into python:main Jun 25, 2024
63 checks passed
@srittau srittau deleted the abspath branch June 25, 2024 12:01
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Avasam added a commit to Avasam/typeshed that referenced this pull request Oct 17, 2024
hauntsaninja pushed a commit that referenced this pull request Oct 17, 2024
Revert "Remove obsolete mypy bug workaround in `abspath()` (#12208)"

This reverts commit 271df8e.
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.

2 participants