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

[WIP] Make ManifestSchema compatible with marshmallow >= 3 #3296

Closed

Conversation

StefanBruens
Copy link

Instead of suppressing the exception, checking for an error and raising
a PlatformIOException, directly raise the PlatformIOException from
handle_error().

Add a small wrapper for Schema.load() to cover the the return value
difference ((data, error) tuple vs data only).

For more information, see
https://marshmallow.readthedocs.io/en/stable/upgrading.html

@StefanBruens StefanBruens force-pushed the marshmallow3_support branch 2 times, most recently from 9dfc3fd to eb42f2c Compare December 2, 2019 13:06
Instead of suppressing the exception, checking for an error and raising
a PlatformIOException, directly raise the PlatformIOException from
handle_error().

Add a small wrapper for Schema.load() to cover the the return value
difference ((data, error) tuple vs data only).

For more information, see
https://marshmallow.readthedocs.io/en/stable/upgrading.html
@ivankravets
Copy link
Member

Could you fix a PR to make it compatible between Python 2 and Python 3?

@StefanBruens StefanBruens changed the title Make ManifestSchema compatible with marshmallow >= 3 [WIP] Make ManifestSchema compatible with marshmallow >= 3 Dec 2, 2019
@StefanBruens
Copy link
Author

Supporting both Python2 and 3 is actually a little bit more work, but I am on it ...


from platformio.package.exception import ManifestValidationError
from platformio.util import memoized


class StrictSchema(Schema):
def handle_error(self, error, data):
def handle_error(self, error, data, *, _many, **_kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.7 doesn't have keyword only arguments

https://www.python.org/dev/peps/pep-3102/

Suggested change
def handle_error(self, error, data, *, _many, **_kwargs):
def handle_error(self, error, data, _many, **_kwargs):

data, _ = self.load(manifest)
return data

def handle_error(self, error, data, *, _many, **_kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def handle_error(self, error, data, *, _many, **_kwargs):
def handle_error(self, error, data, _many, **_kwargs):

No keyword only arguments in Python 2.7

@hmaarrfk
Copy link
Contributor

Sorry for jumping in, just did a quick browse and noticed at least one feature that isn't available in Python 2.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants