-
Notifications
You must be signed in to change notification settings - Fork 0
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
Self-description / metadescriptions #78
Conversation
364b744
to
29c4055
Compare
Magritte/MAContainerTest.py
Outdated
def test_searchByName(self): | ||
desc = MAContainer() | ||
desc += MAStringDescription(name = "first", label = "First Field") | ||
desc += MAStringDescription(label = "nameless #2") |
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.
Кавычки то одинарные, то двойные. Питону всё равно, но рекомендуется использовать одинарные "в простых случаях" - они "легче" выглядят при отсмотре кода.
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.
Не знал.
Но что делать?
Как найти все места с кавычками?
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.
поиском, например,
="
= "
("
,"
, "
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.
так найдётся большая часть
@classmethod | ||
def isAbstract(cls): | ||
return True | ||
|
||
@property | ||
def type(self): |
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.
Зачем это? Нигде не используется.
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.
Используется при сериализации метадескриптора.
То есть представь, у нас есть какой-нибудь Customer
, а у него поле last_name
.
Как из дескриптора поля понять, что это строка?
Вот по полю type
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.
Почему не по kind?
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.
потому что kind возвращает класс - он нужен, но его и описать и сериализовать сложно
Magritte/MADescription_selfdesc.py
Outdated
def magritteDescription(self): | ||
desc = MAPriorityContainer() | ||
|
||
desc += MAStringDescription(label = "Kind", priority = 0, readOnly = True, accessor = MAAttrAccessor('type')) |
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.
Почему не attrAccessor('kind') ?
Magritte/MADescription_selfdesc.py
Outdated
|
||
desc += MAStringDescription(label = "Kind", priority = 0, readOnly = True, accessor = MAAttrAccessor('type')) | ||
desc += MAStringDescription(label = "Field name", priority = 1, accessor = MAAttrAccessor('name'), comment = "Non-human-readable name, something like 'field name' or `json key`, etc.") | ||
desc += MAStringDescription(label = "Label", priority = 100, default = "#nolabel#", required = True, accessor = MAAttrAccessor('label')) |
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.
Почему не defaultLabel() ?
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.
Остатки ранних усилий, кажется. Посмотрю.
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.
- разобраться с "#nolabel#"
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.
Вынес задачу в отдельный тикет #81
Там целая подсистема генерирования label на основе дескриптора, мне не хочется делать её в рамках этого ПРа.
|
||
object_encoder = MAObjectJsonWriter(description.reference) | ||
collection = description.accessor.read(self._model) # TODO: replace on model.readUsing or description.read (both are not implemented yet) |
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.
Уже implemented
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.
- реализовать правильное чтение, без прямого доступа к аксессору
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.
Вынесено в #85
Looks like if you overwrite getter of the @Property, you need also overvrite setter of it - even if it not changed. If you overvrite getter only, setter becomes inaccessible.
refactoring is needed to exclude copy-pasted name-related piece of code
othervise it's pretty hard to determine which exactly descriptor has no label and therefore can't be converted to json
It's non-visible because there is, well, no good way to show it - it's an object. Why #accessor has reference of MAStringDescription I don't know - but it's how it in original I tested it by printing out the value of it, directly by `if description.name == "accessor"` - and result was OK
works with non-json values as accessors
and completely moved into MAElementDescriptor Why they have this pseudo-accessors and why description and default value was in the MADescription - I don't know. Have no good reasons for this.
…ReferenceDescription it has lasy-initialization anyway, and current implementation overrides whatever custom reference we'll set however, laizy initialization fixed, too, to not re-create defaultReference each time we access it
better support of references
additional thoughts are needed to manage them properly
previous approach was needed to overcome reference "init overwriting" bug, which was fixes
this way `children` _may_ be set in constructor's parameters smalltalk original has no constructors or factory methods for descriptions, they use chain calls of setters instead. But we use constructors, hence the modification.
Except of visual-only test we performs seferal self-health checks At least we know every description has a description and that every described field is accessible
29c4055
to
a8c1110
Compare
This reverts commit 860129b.
Just in case `magritteDescription` exists but is not callable...or something
Добавляет дескрипторы для дескрипторов
Даже тесты какие-никакие есть
NB: некоторые сильно особенные поля (типа
reference
илиclasses
) я помечаю (комментариями) как# === special ===
и делаю их типаMAElementDescription
. Типа, обозначить существование полей, беспечить доступ стандартным образом и т.п.