-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: implement from_params
methods
#18
base: main
Are you sure you want to change the base?
Conversation
from_params
methodfrom_params
methods
from devana.syntax_abstraction.classinfo import * | ||
import unittest | ||
|
||
class TestInstanceCreations(unittest.TestCase): |
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.
Please, add failure tests based on some locally created classes in the test body - how it behaves in case of errors. Additionally, it would be good to check in one test that propwerty becomes a property instead of being overwritten with the value of nstrwardo. I know that's how the code currently works, but if it was the first thing I thought of when reading the code as a possible error - it should get a test.
"""Checks if the attribute is directly in the instance or if it's a class attribute, | ||
excluding properties.""" | ||
if hasattr(instance.__class__, name): | ||
if not isinstance(getattr(instance.__class__, name, property()), property): |
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.
You check if an attribute exists, adding a default one in this case is a bit pointless.
try: | ||
maybe_property = getattr(instance.__class__, name) | ||
except AttributeError: |
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.
Maybe it's easier to check if the attribute exists? Unless you're protecting yourself from other errors here?
"""A decorator that assigns method parameters as instance attributes. | ||
The attribute must have a setter or exist as an instance or class variable.""" |
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.
Please document the use of this in a second paragraph and how it is supposed to work technically.
) -> "CodeContainer": | ||
return cls(None, parent) |
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'm not a big fan of this notation. Ultimately it's something I can accept but if you feel like playing/testing you could think of a property on the class that would generate a method that would take all these parameters - then in this function we would call it explicitly.
But that's just thinking out loud.
cls, | ||
parent: Optional = None, | ||
content: Optional = None, | ||
namespace: Optional = None, |
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.
Why namespace is ignored?
@@ -124,6 +137,19 @@ def from_cursor(cls, cursor: cindex.Cursor, parent: Optional = None) -> Optional | |||
result = cls(cursor, parent) | |||
return result | |||
|
|||
@classmethod | |||
@init_params(skip={"cls", "parent"}) |
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.
If we almost always ignore cls and parent maybe we can get rid of that parameter and add it to the implementation?
cls, | ||
parent: Optional = None, | ||
namespaces: Optional = None, | ||
lexicon: Optional = None |
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.
Why isn't this typed?
No description provided.