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

Modernize and remove Python 2.x compatibility code #340

Merged
merged 2 commits into from
May 9, 2024

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Apr 24, 2024

If you feel like it, let's get this one merged first before #339.

@intgr
Copy link
Contributor Author

intgr commented May 3, 2024

Ping @alanjds, any thoughts on this?

Copy link
Owner

@alanjds alanjds left a comment

Choose a reason for hiding this comment

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

Thanks for removing Python 2 compat code.

I left only some stuff that still works with Py 3 and helps on typing for some IDEs

@@ -26,7 +19,7 @@ class NestedHyperlinkedRelatedField(rest_framework.relations.HyperlinkedRelatedF

def __init__(self, *args, **kwargs):
self.parent_lookup_kwargs = kwargs.pop('parent_lookup_kwargs', self.parent_lookup_kwargs)
super(NestedHyperlinkedRelatedField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
super().__init__(*args, **kwargs)
super(NestedHyperlinkedRelatedField, self).__init__(*args, **kwargs)

Copy link
Contributor Author

@intgr intgr May 9, 2024

Choose a reason for hiding this comment

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

I don't mind reverting these, but I doubt it's necessary really.

Which typing tools? I would think they are capable of finding the base class from the class ...(...): definition.

Copy link
Owner

Choose a reason for hiding this comment

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

Looks like at least VSCode have trouble detecting upper classes in some cases, if the middle classes do not put its names in the super().

Well, lets have this merged and revert back if some complains arise 👍

@@ -103,4 +96,4 @@ def __init__(self, view_name=None, **kwargs):
assert view_name is not None, 'The `view_name` argument is required.'
kwargs['read_only'] = True
kwargs['source'] = '*'
super(NestedHyperlinkedIdentityField, self).__init__(view_name=view_name, **kwargs)
super().__init__(view_name=view_name, **kwargs)
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
super().__init__(view_name=view_name, **kwargs)
super(NestedHyperlinkedIdentityField, self).__init__(view_name=view_name, **kwargs)

@@ -27,10 +27,10 @@ class NestedHyperlinkedModelSerializer(rest_framework.serializers.HyperlinkedMod

def __init__(self, *args, **kwargs):
self.parent_lookup_kwargs = kwargs.pop('parent_lookup_kwargs', self.parent_lookup_kwargs)
super(NestedHyperlinkedModelSerializer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
super().__init__(*args, **kwargs)
super(NestedHyperlinkedModelSerializer, self).__init__(*args, **kwargs)


def build_url_field(self, field_name, model_class):
field_class, field_kwargs = super(NestedHyperlinkedModelSerializer, self).build_url_field(
field_class, field_kwargs = super().build_url_field(
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
field_class, field_kwargs = super().build_url_field(
field_class, field_kwargs = super(NestedHyperlinkedModelSerializer, self).build_url_field(

@@ -44,7 +44,7 @@ def get_queryset(self):
Filter the `QuerySet` based on its parents as defined in the
`serializer_class.parent_lookup_kwargs` or `viewset.parent_lookup_kwargs`
"""
queryset = super(NestedViewSetMixin, self).get_queryset()
queryset = super().get_queryset()
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
queryset = super().get_queryset()
queryset = super(NestedViewSetMixin, self).get_queryset()

@@ -11,7 +10,7 @@ class CustomField(models.CharField):

def __init__(self, *args, **kwargs):
kwargs['max_length'] = 12
super(CustomField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
Copy link
Owner

Choose a reason for hiding this comment

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

That part can stay. It helps typing tools.

Suggested change
super().__init__(*args, **kwargs)
super(CustomField, self).__init__(*args, **kwargs)

@alanjds alanjds merged commit a636f45 into alanjds:master May 9, 2024
4 checks passed
@intgr intgr deleted the remove-python2-compat branch May 9, 2024 15:38
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.

2 participants