question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forbid old-styled classes

See original GitHub issue

In python2 we had different classes: class Some: and class Some(object): were totally different things.

Currently, we don’t have this thing in python3, but since these times I believe that new-styled classes are still better.

  1. It has more semantics: this class is related to object
  2. It has unified interface: class Base(object) and class Child(Base) vs class Base and class Child(Base)
  3. Explicit is better than implicit

So, I believe we should ban classes with old-styled base class. General rule is: always write super-classes’ names

Correct

class Philosopher(object):
    def __init_subclass__(cls, default_name, **kwargs):
        ...

class AustralianPhilosopher(Philosopher, default_name="Bruce"):
    ...

class WithMetaClass(object, metaclass=MyMeta):
   ...

Wrong

class Philosopher: ...
class AustralianPhilosopher(default_name="Bruce"): ...
class WithMetaClass(metaclass=MyMeta): ...

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
AlwxSincommented, Jul 11, 2018

Yes, both classes are subclasses

And good developer knows that. But you cannot clearly see the difference between these classes though.

1reaction
AlwxSincommented, Jul 11, 2018

ezgif-2-dc2f4987da

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I prevent automatic body subscripting when using ...
I'm using Overleaf with the tufte-book class to create lecture notes for an aviation course. When departing from Dallas-Fort Worth International ...
Read more >
Embind — Emscripten 3.1.26-git (dev) documentation
Embind is used to bind C++ functions and classes to JavaScript, so that the compiled code can be used in a natural way...
Read more >
Python's Super Considered Harmful - James Y. Knight
This turns out to work fine, as long as the oldstyle classes (that do not use ... If you don't do this, forbid...
Read more >
Oldstyle / Fabian Iwand - Observable
Oldstyle. Allows toggling between the current default CSS and a CSS ... keyword,a[href]{color:#3182bd}.hljs-deletion,.hljs-variable,.observablehq--forbidden ...
Read more >
Prevent EntityManager persisting| JBoss.org Content Archive (Read ...
@Stateless public class MyClassBean implements MyClass ... The idea that session beans are never used in the presentation tier is oldstyle EJB2 thinking....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found