Skip to content

Conversation

@not-my-profile
Copy link
Contributor

The signatures of these functions can also be modeled
without overloads using unions as parameter types.

While this shouldn't make any difference for type checking,
it improves the UX for people using IDEs because having to
cycle between subtly different function signatures isn't fun.

The signatures of these functions can also be modeled
without overloads using unions as parameter types.

While this shouldn't make any difference for type checking,
it improves the UX for people using IDEs because having to
cycle between subtly different function signatures isn't fun.
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/strings/object_array.py:216: error: Value of type variable "AnyStr" of "compile" cannot be "Union[str, Pattern[Any], Any]"  [type-var]
+ pandas/core/array_algos/replace.py:88: error: Value of type variable "AnyStr" of "search" cannot be "Union[str, Pattern[Any], Any]"  [type-var]

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/docstrings.py:20:22: error: Value of type variable "AnyStr" of "compile" cannot be "Union[str, Pattern[Any], Any]"
+ sphinx/util/docstrings.py: note: In function "separate_metadata":
+ sphinx/util/docstrings.py:39:30: error: Value of type "Union[str, Pattern[Any], Any]" is not indexable
+ sphinx/testing/util.py: note: In function "assert_re_search":
+ sphinx/testing/util.py:34:12: error: Value of type variable "AnyStr" of "search" cannot be "Union[str, Pattern[Any], Any]"
+ sphinx/testing/util.py: note: In function "assert_not_re_search":
+ sphinx/testing/util.py:39:8: error: Value of type variable "AnyStr" of "search" cannot be "Union[str, Pattern[Any], Any]"

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 22, 2022

See also:

Unfortunately, there's a number of mypy bugs regarding constrained TypeVars that make this hard to do right now, even though these functions probably should be typed like this ☹

@not-my-profile
Copy link
Contributor Author

Ah, well ... how unfortunate that mypy has such a limitation. I guess the tracking issue for that is python/mypy#11880?

@AlexWaygood
Copy link
Member

Ah, well ... how unfortunate that mypy has such a limitation. I guess the tracking issue for that is python/mypy#11880?

Yup 🙂 it might be good to add a comment to the re module functions and bool, to explain why they're typed the way they currently are — it's obviously pretty unintuitive for contributors.

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