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.

False positive DirectMagicAttributeAccessViolation with __subclasses__

See original GitHub issue

Bug report

What’s wrong

class MyClass(object):
    """My class."""

subs = MyClass.__subclasses__()

This piece of code raises WPS609 Found direct magic attribute usage: __subclasses__

How is that should be

__subclasess__ method should be excluded from the check because it’s a class method and can be used outside of class.

Maybe there are other methods that should be excluded?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sobolevncommented, Apr 17, 2020

@AlwxSin submit a PR then 🛷

1reaction
sobolevncommented, Apr 8, 2020

@mattany thanks a lot! And congrats on your first open-source fork 🎉

I am going to help you!

  1. We need to find the violation that @AlwxSin is talking about. It can be done even inside Github’s search: https://github.com/wemake-services/wemake-python-styleguide/search?q=DirectMagicAttributeAccessViolation&unscoped_q=DirectMagicAttributeAccessViolation
  2. Then we locate that it is used in four files: we are only interested in visitors. Read more about our architecture here: https://wemake-python-stylegui.de/en/latest/pages/api/index.html#overview
  3. Then we find the exact place where this violation is raised in the visitor: https://github.com/wemake-services/wemake-python-styleguide/blob/58b96219a39390c35353aa9a29d483d5ed3f1cf7/wemake_python_styleguide/visitors/ast/attributes.py#L67

And let’s start from here: we can create a whitelist of method names that can be called. And do not raise violation if this method name is inside the whitelist.

Feel free to ask any questions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Guide to Python's Magic Methods « rafekettler.com
A guide to all the Magic Methods in Python. ... Representing your Classes; Controlling Attribute Access; Making Custom Sequences; Reflection ...
Read more >
3. Data model — Python 3.11.1 documentation
These are attributes that provide access to the implementation and are not intended for general use. Their definition may change in the future....
Read more >
Python Tutorial - Object-Oriented Programming (OOP)
To access an attribute, use "dot" operator in the form of class_name.attr_name or instance_name.attr_name . To construct an instance of a class, invoke...
Read more >
Underscoring (or dunder-scoring) the importance of native ...
And all Python objects have a type with associated attributes and ... data types using something known as dunder methods or magic methods....
Read more >
2. Class vs. Instance Attributes | OOP | python-course.eu
Object-oriented programming in Python: instance attributes vs. class ... Besides this, we see that we can access a class attribute via an ...
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