-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed as not planned
Labels
reason: inexpressibleClosed, because this can't be expressed within the current type systemClosed, because this can't be expressed within the current type system
Description
The following invalid code type checks in mypy and pyright:
# test.py
import re
obj1 = re.Pattern()
$ mypy test.py
Success: no issues found in 1 source file
$ mypy --version
mypy 1.17.1 (compiled: yes)
$ pyright test.py
0 errors, 0 warnings, 0 informations
$ pyright --version
pyright 1.1.403
At runtime, this would fail with TypeError: cannot create 're.Pattern' instances
.
As a test, I modified the typeshed stub for Pattern
to inherit from Protocol so the lack of a __call__
definition would be caught. No doubt this is a naive approach (nothing is ever so simple), but it seems to work:
- class Pattern(Generic[AnyStr]):
+ class Pattern(Generic[AnyStr], Protocol):
$ mypy test.py
test.py:3: error: Cannot instantiate protocol class "Pattern" [misc]
Found 1 error in 1 file (checked 1 source file)
$ pyright test.py
/path/to/test.py
/path/to/test.py:3:1 - error: Cannot instantiate Protocol class "Pattern" (reportAbstractUsage)
1 error, 0 warnings, 0 informations
Aside from re.Pattern
and re.Match
I'm not sure if there are other types in the stdlib that are not callable but also not ABC's, so this may be a special case.
Metadata
Metadata
Assignees
Labels
reason: inexpressibleClosed, because this can't be expressed within the current type systemClosed, because this can't be expressed within the current type system