Page MenuHomeSoftware Heritage

Add a SWH_MODEL_OBJECT_TYPES map {cls.objet_type: cls} in model.py
ClosedPublic

Authored by douardda on Apr 8 2022, 12:46 PM.

Details

Summary

it's a piece of information used several times in the swh stack.

Diff Detail

Repository
rDMOD Data model
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D7536 (id=27326)

Rebasing onto ba7af7447e...

Current branch diff-target is up to date.
Changes applied before test
commit c2c1c605aa4b43f995e08e60ac13fcda0b6aec42
Author: David Douard <david.douard@sdfa3.org>
Date:   Fri Apr 8 12:42:54 2022 +0200

    Add a SWH_MODEL_OBJECT_TYPES map {cls.objet_type: cls} in model.py
    
    it's a piece of information used several times in the swh stack.

See https://jenkins.softwareheritage.org/job/DMOD/job/tests-on-diff/469/ for more details.

vlorentz added inline comments.
swh/model/model.py
1523–1524

Wouldn't this work?

If not, use type instead of Type[BaseModel]

swh/model/model.py
1523–1524

with the proposed annotation, mypy is unhappy because '"type" has no attribute "object_type"'
No idea how to "fix" this... cannot add an "object_type" to BaseModel (because Final) so no idea how to properly declare this...

swh/model/model.py
1523–1524

would need to be able to declare the object_type on BaseModel as "pure abstract Final" or something I guess.

swh/model/model.py
1523–1524

I tried to declare (but initialize) object_type on BaseModel as:

class BaseModel:
    object_type: Final[str]

but then mypy complains because "Final name must be initialized with a value"

swh/model/model.py
1523–1524

just this:

class BaseModel:
    object_type: str

or you can keep # type: ignore on the SWH_MODEL_OBJECT_TYPES definition (but keep the type annotation, as it will be useful to users of the dict)

swh/model/model.py
1523–1524

just this:

class BaseModel:
    object_type: str

already tried this last week:

error: Cannot override writable attribute "object_type" with a final one

for each model class definition.

or you can keep # type: ignore on the SWH_MODEL_OBJECT_TYPES definition (but keep the type annotation, as it will be useful to users of the dict)

ah, took me some time to get what you mean, ok will try this.

Add type annotation for SWH_MODEL_OBJECT_TYPES

even if we still need the \#type ignore stanza...

This revision is now accepted and ready to land.Apr 11 2022, 10:27 AM

Build is green

Patch application report for D7536 (id=27356)

Rebasing onto 9231cd0d62...

First, rewinding head to replay your work on top of it...
Applying: Add a SWH_MODEL_OBJECT_TYPES map {cls.objet_type: cls} in model.py
Changes applied before test
commit 193df45b5990682a355fb13a041f9874ba9904f7
Author: David Douard <david.douard@sdfa3.org>
Date:   Fri Apr 8 12:42:54 2022 +0200

    Add a SWH_MODEL_OBJECT_TYPES map {cls.objet_type: cls} in model.py
    
    it's a piece of information used several times in the swh stack.

See https://jenkins.softwareheritage.org/job/DMOD/job/tests-on-diff/470/ for more details.

Build is green

Patch application report for D7536 (id=27357)

Rebasing onto 9231cd0d62...

Current branch diff-target is up to date.
Changes applied before test
commit 85f36f84347af09b4a6a097b553b24299c0d7110
Author: David Douard <david.douard@sdfa3.org>
Date:   Fri Apr 8 12:42:54 2022 +0200

    Add a SWH_MODEL_OBJECT_TYPES map {cls.objet_type: cls} in model.py
    
    it's a piece of information used several times in the swh stack.

See https://jenkins.softwareheritage.org/job/DMOD/job/tests-on-diff/471/ for more details.