-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Generic subclass. ABCMeta object is not subscriptable #5264
Comments
This is a known limitation of Python standard library classes. There is a slightly less hacky solution: if TYPE_CHECKING:
QueueBase = queue.Queue
else
class _Queue:
def __getitem__(*args):
return queue.Queue
QueueBase = _Queue() In addition, for your particular use case (non-generic subclass) you can simply write: if TYPE_CHECKING:
Base = UserList[BaseService]
else:
Base = UserList But the latter solution will work only if you don't have type variables. |
Ah, that's it! Thanks for clarifying. I think this should be part of the docs (or maybe at least reference to this answer or something). Closing the issue. |
* ABCMeta typing issue with requests package * python/mypy#5264 (comment) * Run pytest and remove broken test as functionality was removed.
* ABCMeta typing issue with requests package * python/mypy#5264 (comment) * Run pytest and remove broken test as functionality was removed.
I ended up doing sth similar to what @ilevkivskyi did, found this in mypy docs T = TypeVar("T")
if TYPE_CHECKING:
class _Queue(Queue[T]):
pass
else:
class _Queue(Generic[T], Queue):
pass
class BaseQueue(_Queue[T]):
pass |
Please provide more information to help us understand the issue:
I'm trying to write the following
However, that leaves me with
I know that for simple type annotations I can simply define the type in strings in cases like this. However, that clearly doesn't apply in the inheritance case.
The only solution that I found to that seems very hacky.
Since I want to enable
--disallow-any-generics
I need to specify the type parameter for UserList.I'm wondering if there's any other alternative to that?
The text was updated successfully, but these errors were encountered: