PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] How do I get rid of djangorestframework Serializer Abstract class warning in Pycharm?

 April 27, 2022     django, django-rest-framework, pycharm, python-3.x, warnings     No comments   

Issue

I noticed a warning in Pycharm that won't go a way in my Django project. Only think I can find is a link to it being a PyCharm bug... back in 2016

In my class:

class MySerializer(serializers.Serializer):
    ...

I get the following warning:

Class MySerializer must implement all abstract methods

When I do the quick fix suggested so it ends up looking like one of the following:

class MySerializer(serializers.Serializer, ABC):
    ...
# or
class MySerializer(serializers.Serializer, metaclass=ABCMeta):
    ...
# or
class MySerializer(serializers.Serializer):
    # have update or create defined in serializer.
    def update(self, instance, validated_data):
        pass
    
    def create(self, validated_data):
        pass

But this just breaks the project and I'm not too sure what's happening here if I'm being honest or why it wants one of the above solutions to suppress the warning. Is it really a PyCharm bug or am I doing something wrong?


Solution

PyCharm has a lot of warnings. In the end, it all depends on the developers and convention they are following. For example, PyCharm will always report camelCase, but a lot of python built-in libraries use camelCase for naming - no big deal.

You didn't do anything wrong, you might implement those methods, or simply suppress the warnings:

  1. Go to preferences
  2. Write 'abstract' in search box (top-left)
  3. You'll see Inspections > Python > Class must implement all abstract methods
  4. Uncheck it


Answered By - nenadp
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing