| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [case test_assign_to_dunder_class] | ||
|
Comment thread
Copy link
Copy Markdown
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityFor some historical reason, all our testcases use camelCase naming scheme. Also I don't think this deserves its own file, probably just appending to check-statements.test would be more reasonable.
Sorry, something went wrong.
All reactions
|
||
| class A: | ||
| def foo(self): | ||
| self.__class__ = B # E: Assignment to '__class__' is unsafe and not allowed | ||
|
Comment thread
Copy link
Copy Markdown
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPlease also add testcases with non-self assignments and assignments to self.__class__ in __init__ (they're slightly different AFAIC). I'd also love to see tests where this is assigned to various other destinations: b = object()
b.__class__ = something
class A:
__class__ = something
# etc.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| class B: | ||
| pass | ||
|
|
||
| [case test_assign_to_other_dunder_attributes] | ||
| class C: | ||
| def bar(self): | ||
| self.__name__ = "NewName" # OK | ||
| self.__doc__ = "Test doc" # OK | ||
|
|
||
| class D: | ||
| pass | ||
|
|
||
| [case test_assign_to_regular_attribute] | ||
|
Comment thread
Copy link
Copy Markdown
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWe certainly already have tests checking that.
Sorry, something went wrong.
All reactions
|
||
| class E: | ||
| x = 1 | ||
| def baz(self): | ||
| self.x = 2 # OK | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis wording is too strong - assignments are fine themselves, there's nothing inherently unsafe with doing this, it's not a security vuln. Probably something along the lines of
(probably accompanied by a self.note explaining it further) would be less intrusive.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.