Giter Site home page Giter Site logo

Comments (10)

xquek avatar xquek commented on June 2, 2024 1

thank @vemel, let me know if there is anything you need help with ! happy to contribute!

from mypy_boto3_builder.

xquek avatar xquek commented on June 2, 2024 1

hi @vemel sorry for the wait. Work been busy. I put out a draft PR at #233

While implmenting, i realised the cloudwatch notification for event bridge has lots of nested structs and different example. Maybe it might be reasonable to use Type.DictStrAny as you had in your example above.

Also can i check - there are some fields that are enums values, currently i have use type.str - let me know if i using Literal is preferred. Thanks!

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

Hello! Thank you for the feature request.

Unfortunately, botocore shapes use String type for Event shape, so event structure cannot be parsed from botocore shapes. However, event TypeDef can always be hardcoded manually. I will take a look at how to implement it properly.

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

So, it is a tricky change. Events are strings, so this type will not be directly used in any cloudwatch methods.
Another thing is that there is no way to track if botocore changes the output format in any way.

Thank you for your participation in the project!

If you want to prepare a pull request:

CloudwatchEventTypeDef = TypeTypedDict(
    "CloudwatchEventTypeDef",
    [
        TypedDictAttribute("version", Type.str, True),
        ...
    ],
)
  • add new types to service_package in parse_service_package, somewhere around result.type_defs = result.extract_type_defs(), use ServiceNameCatalog to check what service you are working with
  • it makes sense to move TypeDefSorter(self._get_sortable_type_defs()).sort() to parse_service_package.

So end result in parse_service_package should be smth like

type_defs = self._get_sortable_type_defs()
if service_name == ServiceNameCatalog.cloudwatch:
   type_defs.add(CloudwatchEventTypeDef)
# probably we need eventbridge service as well
   
type_def_sorter = TypeDefSorter(self._get_sortable_type_defs())
result.type_defs = type_def_sorter.sort()

Generate and install package to cross-check:

  • generate: ./scripts/build.sh -s cloudwatch --product boto3-services
  • install: ./scripts/install.sh cloudwatch
  • test on your sample, try to import it from mypy_boto3_cloudwatch.type_defs import CloudwatchEventTypeDef

Please let me know if you find this helpful or if you are stuck.

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

TypedDicts should be something like

CloudwatchEventStateTypeDef = TypeTypedDict(
    "CloudwatchEventStateTypeDef",
    [
        TypedDictAttribute("reason", Type.str, True),
        TypedDictAttribute("reasonData", Type.str, True),
        TypedDictAttribute("timestamp", Type.str, True),
        TypedDictAttribute("value", Type.str, True),
    ],
)

CloudwatchEventMetricTypeDef = TypeTypedDict(
    "CloudwatchEventMetricTypeDef",
    [
        TypedDictAttribute("id", Type.str, True),
        TypedDictAttribute(
            "metricStat", Type.DictStrAny, True
        ),  # probably we can improve typing here
        TypedDictAttribute("returnData", Type.bool, True),
    ],
)

CloudwatchEventConfigurationTypeDef = TypeTypedDict(
    "CloudwatchEventDetailConfigurationTypeDef",
    [
        TypedDictAttribute("description", Type.str, True),
        TypedDictAttribute("metrics", TypeSubscript(Type.List, [Type.str]), True),
    ],
)

CloudwatchEventDetailTypeDef = TypeTypedDict(
    "CloudwatchEventDetailTypeDef",
    [
        TypedDictAttribute("alarmName", Type.str, True),
        TypedDictAttribute("configuration", CloudwatchEventConfigurationTypeDef, True),
        TypedDictAttribute("previousState", CloudwatchEventStateTypeDef, True),
        TypedDictAttribute("state", CloudwatchEventStateTypeDef, True),
    ],
)

CloudwatchEventTypeDef = TypeTypedDict(
    "CloudwatchEventTypeDef",
    [
        TypedDictAttribute("version", Type.str, True),
        TypedDictAttribute("id", Type.str, True),
        TypedDictAttribute("detail-type", Type.str, True),
        TypedDictAttribute("source", Type.str, True),
        TypedDictAttribute("account", Type.str, True),
        TypedDictAttribute("time", Type.str, True),
        TypedDictAttribute("region", Type.str, True),
        TypedDictAttribute("resources", TypeSubscript(Type.List, [Type.str]), True),
        TypedDictAttribute("detail", CloudwatchEventDetailTypeDef, True),
    ],
)

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

I made some changes toServicePackageParser, so it is more refactoring-friendly now. Please let me know if you have time for a pull request.

from mypy_boto3_builder.

xquek avatar xquek commented on June 2, 2024

hi vemel, thanks for the pointers! i will have time for a PR this week - but it looks like you already have the implementation above and i dont want to slow you down.

I can work to improve metricStat if you want to merge what you already have above.

Or if you dont mind waiting, i should be able to get them out in the next few days.

Thanks!! let me know!

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

I definitely do not mind waiting, it is not an urgent change. Take your time.

Once again, if you are stuck - please let me know.

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

@xquek Hello! Do you have any updates?

from mypy_boto3_builder.

vemel avatar vemel commented on June 2, 2024

Thank you for your contribution. I added your TypeDefs to cloudwatch service stubs. Please let me know if it works for you.

from mypy_boto3_builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.