-
Notifications
You must be signed in to change notification settings - Fork 164
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
Conversation
Ping @alanjds, any thoughts on this? |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
super().__init__(*args, **kwargs) | |
super(NestedHyperlinkedRelatedField, self).__init__(*args, **kwargs) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
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( |
There was a problem hiding this comment.
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.
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() |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
super().__init__(*args, **kwargs) | |
super(CustomField, self).__init__(*args, **kwargs) |
If you feel like it, let's get this one merged first before #339.