Skip to content
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

Merged
merged 37 commits into from
Sep 25, 2023
Merged

Conversation

Assargadon
Copy link
Owner

Добавляет дескрипторы для дескрипторов
Даже тесты какие-никакие есть

NB: некоторые сильно особенные поля (типа reference или classes) я помечаю (комментариями) как # === special === и делаю их типа MAElementDescription. Типа, обозначить существование полей, беспечить доступ стандартным образом и т.п.

def test_searchByName(self):
desc = MAContainer()
desc += MAStringDescription(name = "first", label = "First Field")
desc += MAStringDescription(label = "nameless #2")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кавычки то одинарные, то двойные. Питону всё равно, но рекомендуется использовать одинарные "в простых случаях" - они "легче" выглядят при отсмотре кода.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не знал.
Но что делать?
Как найти все места с кавычками?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поиском, например,
="
= "
("
,"
, "

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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем это? Нигде не используется.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используется при сериализации метадескриптора.
То есть представь, у нас есть какой-нибудь Customer, а у него поле last_name.

Как из дескриптора поля понять, что это строка?
Вот по полю type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не по kind?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

потому что kind возвращает класс - он нужен, но его и описать и сериализовать сложно

def magritteDescription(self):
desc = MAPriorityContainer()

desc += MAStringDescription(label = "Kind", priority = 0, readOnly = True, accessor = MAAttrAccessor('type'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не attrAccessor('kind') ?


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'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не defaultLabel() ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Остатки ранних усилий, кажется. Посмотрю.

Copy link
Owner Author

@Assargadon Assargadon Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • разобраться с "#nolabel#"

Copy link
Owner Author

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уже implemented

Copy link
Owner Author

@Assargadon Assargadon Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • реализовать правильное чтение, без прямого доступа к аксессору

Copy link
Owner Author

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
@Assargadon Assargadon merged commit 033279a into python_magritte Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants