Skip to content
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

Enhance reportInvalidTypeVarUse to report situations where class-scoped TypeVars may go unsolved in constructor #3501

Closed
erictraut opened this issue May 24, 2022 · 8 comments
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@erictraut
Copy link
Collaborator

This is similar to #3495 but applies to constructors and class-scoped TypeVars.

@erictraut erictraut added the enhancement request New feature or request label May 24, 2022
@erictraut
Copy link
Collaborator Author

@JelleZijlstra, I've implemented this expanded check. It reports an additional 32 errors within typeshed (in addition to the 37 errors reported for function-scoped TypeVars that may go unsolved).

Here's a full list of the errors, which includes both of the above:

/typeshed/stdlib/_weakrefset.pyi
  /typeshed/stdlib/_weakrefset.pyi:15:39 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "data"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/argparse.pyi
  /typeshed/stdlib/argparse.pyi:215:32 - error: Type variable "_ArgumentParserT" may go unsolved if caller supplies no argument for parameter "parser_class"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/array.pyi
  /typeshed/stdlib/array.pyi:24:94 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "__initializer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/array.pyi:26:98 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "__initializer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/array.pyi:28:98 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "__initializer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/array.pyi:30:71 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "__initializer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/builtins.pyi
  /typeshed/stdlib/builtins.pyi:965:45 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "__iterable"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/builtins.pyi:1001:45 - error: Type variable "_T_co" may go unsolved if caller supplies no argument for parameter "__iterable"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/contextvars.pyi
  /typeshed/stdlib/contextvars.pyi:17:47 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "default"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/difflib.pyi
  /typeshed/stdlib/difflib.pyi:32:33 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "isjunk"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/fileinput.pyi
  /typeshed/stdlib/fileinput.pyi:32:54 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "openhook"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/fileinput.pyi:75:58 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "openhook"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/gettext.pyi
  /typeshed/stdlib/gettext.pyi:157:22 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "class_"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/graphlib.pyi
  /typeshed/stdlib/graphlib.pyi:14:45 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "graph"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/mailbox.pyi
  /typeshed/stdlib/mailbox.pyi:50:66 - error: Type variable "_MessageT" may go unsolved if caller supplies no argument for parameter "factory"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/optparse.pyi
  /typeshed/stdlib/optparse.pyi:243:41 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "args"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/subprocess.pyi
  /typeshed/stdlib/subprocess.pyi:135:61 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "stdout"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/tempfile.pyi
  /typeshed/stdlib/tempfile.pyi:366:21 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "suffix"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/tempfile.pyi:387:13 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "suffix"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/tempfile.pyi:392:21 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "suffix"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/tempfile.pyi:396:20 - error: Type variable "AnyStr" may go unsolved if caller supplies no argument for parameter "suffix"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/collections/__init__.pyi
  /typeshed/stdlib/collections/__init__.pyi:85:43 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "initlist"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/collections/__init__.pyi:217:43 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "iterable"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/ctypes/__init__.pyi
  /typeshed/stdlib/ctypes/__init__.pyi:167:29 - error: Type variable "_CT" may go unsolved if caller supplies no argument for parameter "arg"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/ctypes/__init__.pyi:193:31 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "value"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/multiprocessing/managers.pyi
  /typeshed/stdlib/multiprocessing/managers.pyi:127:38 - error: Type variable "_KT" may go unsolved if caller supplies no argument for parameter "sequence"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/multiprocessing/managers.pyi:127:43 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "sequence"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stdlib/multiprocessing/managers.pyi:128:39 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "sequence"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stdlib/multiprocessing/shared_memory.pyi
  /typeshed/stdlib/multiprocessing/shared_memory.pyi:26:43 - error: Type variable "_SLT" may go unsolved if caller supplies no argument for parameter "sequence"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi
  /typeshed/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi:117:76 - error: Type variable "_DeclT" may go unsolved if caller supplies no argument for parameter "metaclass"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi:128:37 - error: Type variable "_DeclT" may go unsolved if caller supplies no argument for parameter "metaclass"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi
  /typeshed/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi:94:36 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "d"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/beautifulsoup4/bs4/element.pyi
  /typeshed/stubs/beautifulsoup4/bs4/element.pyi:354:63 - error: Type variable "_PageElementT" may go unsolved if caller supplies no argument for parameter "result"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/cachetools/cachetools/__init__.pyi
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:14:61 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:34:61 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:37:61 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:40:61 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:43:61 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:47:58 - error: Type variable "_KT" may go unsolved if caller supplies no argument for parameter "choice"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:47:105 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:54:86 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/cachetools/cachetools/__init__.pyi:70:98 - error: Type variable "_VT" may go unsolved if caller supplies no argument for parameter "getsizeof"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/contextvars/contextvars.pyi
  /typeshed/stubs/contextvars/contextvars.pyi:14:47 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "default"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi
  /typeshed/stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi:21:32 - error: Type variable "TConfig" may go unsolved if caller supplies no argument for parameter "config"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/invoke/invoke/tasks.pyi
  /typeshed/stubs/invoke/invoke/tasks.pyi:75:17 - error: Type variable "_TaskT" may go unsolved if caller supplies no argument for parameter "klass"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/mock/mock/mock.pyi
  /typeshed/stubs/mock/mock/mock.pyi:233:14 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "new"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/mypy-extensions/mypy_extensions.pyi
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:24:15 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:25:22 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:26:20 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:27:27 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:28:18 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/mypy-extensions/mypy_extensions.pyi:29:17 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "type"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/psycopg2/psycopg2/_psycopg.pyi
  /typeshed/stubs/psycopg2/psycopg2/_psycopg.pyi:409:62 - error: Type variable "_T_cur" may go unsolved if caller supplies no argument for parameter "cursor_factory"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/redis/redis/commands/core.pyi
  /typeshed/stubs/redis/redis/commands/core.pyi:644:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:651:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:682:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:689:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:859:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:874:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:901:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:935:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:958:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:1023:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:1038:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:1065:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:1099:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/redis/redis/commands/core.pyi:1122:47 - error: Type variable "_ScoreCastFuncReturn" may go unsolved if caller supplies no argument for parameter "score_cast_func"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
/typeshed/stubs/setuptools/pkg_resources/__init__.pyi
  /typeshed/stubs/setuptools/pkg_resources/__init__.pyi:63:104 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "installer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
  /typeshed/stubs/setuptools/pkg_resources/__init__.pyi:67:83 - error: Type variable "_T" may go unsolved if caller supplies no argument for parameter "installer"
    Provide an overload that specifies the return type when the argument is not supplied (reportInvalidTypeVarUse)
69 errors, 0 warnings, 0 informations 

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label May 24, 2022
@erictraut
Copy link
Collaborator Author

erictraut commented May 24, 2022

@JelleZijlstra, I'm having second thoughts about this expanded check. I think it may result in less type safe code.

The problem is that if you make changes to typeshed to eliminate the above errors, I presume you'll do so by explicitly supplying an Any type argument in many of these cases. That will propagate Any types, which will go undetected even in pyright's strict type checking mode. In contrast, today the unsolved TypeVar will result in an Unknown (implicit Any) type argument, and the user will be alerted to the type checking hole. They can then provide an explicit specialization for the class when calling the constructor.

For example, here's the current constructor for UserList

class UserList(MutableSequence[_T]):
    def __init__(self, initlist: Iterable[_T] | None = ...) -> None: ...

To eliminate the new error, it will need to be changed to:

class UserList(MutableSequence[_T]):
    @overload
    def __init__(self, initlist: Iterable[_T]) -> None: ...
    @overload
    def __init__(self: UserList[Any], initlist: None = ...) -> None: ...

Previously, a user could have used:

x1 = UserList()
reveal_type(x1) # UserList[Unknown]
x2 = UserList[int]()
reveal_type(x2) # UserList[int]

Now, this will result in the following:

x1 = UserList()
reveal_type(x1) # UserList[Any]
x2 = UserList[int]()
reveal_type(x2) # UserList[Any]

This seems like a step backward, so I'm inclined to revert this change. What do you think?

I suppose the error could be eliminated without adding an explicit Any:

class UserList(MutableSequence[_T]):
    @overload
    def __init__(self, initlist: Iterable[_T]) -> None: ...
    @overload
    def __init__(self, initlist: None = ...) -> None: ...

But this will still result in an unsolved TypeVar, which defeats the purpose of adding an overload and flagging the original constructor declaration as an inappropriate use of a TypeVar.

@erictraut erictraut added needs decision and removed addressed in next version Issue is fixed and will appear in next published version labels May 24, 2022
@JelleZijlstra
Copy link
Contributor

Yes, empty collections are a tricky situation. Looking at the collection builtins, there are three options:

list has an overload that doesn't use its TypeVar (https://github.com/python/typeshed/blob/c1aba8059f8386230ec7d467e40c86b31eba8c7f/stdlib/builtins.pyi#L865):

    @overload
    def __init__(self) -> None: ...

dict has an overload that sets its TypeVars but leaves them unconstrained:

    @overload
    def __init__(self: dict[_KT, _VT]) -> None: ...

set and frozenset use a defaulted parameter with a TypeVar (https://github.com/python/typeshed/blob/c1aba8059f8386230ec7d467e40c86b31eba8c7f/stdlib/builtins.pyi#L965):

    def __init__(self, __iterable: Iterable[_T] = ...) -> None: ...

Only the set option gets flagged by your new check, but pyright's reportUnknownVariableType check flags all of x = list(), x = dict(), x = set(). So if we switch to the list or dict option, we can fix the unconstrained TypeVar while keeping the same degree of type safety.

Do you have a preference between the list and dict option? They appear to behave the same in both pyright and mypy; I'd favor the list option for being less code.

@saaketp
Copy link

saaketp commented May 24, 2022

@JelleZijlstra If after making the change, there would still be unsolved TypeVar anyway, then we could just ignore the error too, instead of adding overloads.

And is it only empty collections where this will be an issue?
I kinda suspect a lot of times there won't be any solution other than Any for the T, so this check will lead to lots of false positives, and require unnecessary overloads that still leave the T unsolved, if we want to avoid Any.
(Plus adding overloads has other costs, like incompatibility with ParamSpec and performance (I guess?) and a bit too too verbose (for inline annotations at least)).

@JelleZijlstra
Copy link
Contributor

Many cases (e.g., FileInput) do have correct solutions when the default is used. I think it's worth it to add this check to help us catch such cases.

@saaketp
Copy link

saaketp commented May 24, 2022

Okay well at least it is a separate rule, so can be enabled/disabled by choice without affecting other rules.
So worth having definitely.
Just may not be a good idea to be enabled by default.

@erictraut
Copy link
Collaborator Author

we can fix the unconstrained TypeVar while keeping the same degree of type safety.

OK, you've convinced me that we should leave this new check in place. I reserve the right to revert it if we get a backlash from pyright users, but I'm willing to publish a new version with this check in place.

Do you have a preference between the list and dict option?

I don't have a preference between these two. They both seem fine to me.

@erictraut
Copy link
Collaborator Author

This is addressed in pyright 1.1.249, which I just published. It will also be included in the next release of pylance.

AlexWaygood pushed a commit to python/typeshed that referenced this issue May 25, 2022
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 27, 2022
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 27, 2022
- TypeVar changes from microsoft/pyright#3501
- Fix pos-only param
- Use protocols instead of IO classes
AlexWaygood pushed a commit to python/typeshed that referenced this issue May 27, 2022
AlexWaygood pushed a commit to python/typeshed that referenced this issue May 27, 2022
- TypeVar changes from microsoft/pyright#3501
- Fix pos-only param
- Use protocols instead of IO classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants