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

TypeError: 'type' object is not subscriptable #336

Closed
Omri-Ben-Yair opened this issue Dec 24, 2024 · 3 comments
Closed

TypeError: 'type' object is not subscriptable #336

Omri-Ben-Yair opened this issue Dec 24, 2024 · 3 comments
Labels
🐞 bug Something isn't working 🎉 released Changes were included to the latest release 👋 response needed Awaiting response from a reporter

Comments

@Omri-Ben-Yair
Copy link

Omri-Ben-Yair commented Dec 24, 2024

Describe the bug
Recently the type annotations changed from using typing Dict to just dict, this breaks support for python 3.8

The bug was introduced in mypy-boto3-glue = 1.35.87, it did not exists in 1.35.80, so probably introduced on Dec 12 by this commit

Only python > 3.9 support dict in type annotations.

The type looks like:

class RecipeActionOutputTypeDef(TypedDict):
    Operation: str
    Parameters: NotRequired[dict[str, str]]

To Reproduce
Steps to reproduce the behavior:

  1. install mypy-boto3-glue = "1.35.87"
  2. try to import a type which uses a dict like SchemaVersionListItemTypeDef, it will get an error on import phase
from mypy_boto3_glue.type_defs import SchemaVersionListItemTypeDef
...

Actual output

Traceback (most recent call last):
    from mypy_boto3_glue.type_defs import SchemaVersionListItemTypeDef
  File "project1/.venv/lib/python3.8/site-packages/mypy_boto3_glue/__init__.py", line 79, in <module>
    from .client import GlueClient
  File "project1/.venv/lib/python3.8/site-packages/mypy_boto3_glue/client.py", line 28, in <module>
    from .paginator import (
  File "project1/.venv/lib/python3.8/site-packages/mypy_boto3_glue/paginator.py", line 88, in <module>
    from .type_defs import (
  File "project1/.venv/lib/python3.8/site-packages/mypy_boto3_glue/type_defs.py", line 1863, in <module>
    "Parameters": NotRequired[dict[str, str]],
TypeError: 'type' object is not subscriptable

Additional context
Mac OS, python 3.8.16.
mypy-boto3-glue = 1.35.87

@Omri-Ben-Yair Omri-Ben-Yair added the 🐞 bug Something isn't working label Dec 24, 2024
@vemel
Copy link
Collaborator

vemel commented Dec 25, 2024

Hello! Thanks you for the report. All TypeDefs now use py39+ type annotations.

It is recommended to put mypy_boto3_* import into TYPE_CHECKING. This way you can make it work on py38, since all popular type checkers support subscriptable types.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
   from mypy_boto3_glue.type_defs import SchemaVersionListItemTypeDef

If you use TypeDefs for something else, e. g., inheritance or runtime checks, add a fallback:

if TYPE_CHECKING:
   from mypy_boto3_glue.type_defs import SchemaVersionListItemTypeDef
else:
   SchemaVersionListItemTypeDef = object

Let me know if this works for you, or if you have a scenario in which it does not work.

@Omri-Ben-Yair
Copy link
Author

Thanks for the clarification @vemel .

@vemel
Copy link
Collaborator

vemel commented Jan 7, 2025

@Omri-Ben-Yair With the latest mypy-boto3-glue release you can use types in runtime on Python 3.8 like before. Please let me know if it works in your case.

@vemel vemel added 👋 response needed Awaiting response from a reporter 🎉 released Changes were included to the latest release labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🎉 released Changes were included to the latest release 👋 response needed Awaiting response from a reporter
Projects
None yet
Development

No branches or pull requests

2 participants