question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Metadata API: Metadata "factory" constructors misbehave with inheritance

See original GitHub issue
class DerivedMetadata(Metadata):
    def ok(self):
        print("ok")

md = DerivedMetadata.from_file("root.json")
md.ok() # fails because md type is Metadata, not DerivedMetadata

This seems to happen because the construction path goes

  • DerivedMetadata.from_file()
  • DerivedMetadata.from_bytes()
  • JsonDeserializer.deserialize() here deserializer doesn’t know the correct class anymore and calls Metadata.from_dict()
  • Metadata.from_dict()

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
lukpuehcommented, Nov 10, 2021

@jku, unless you need this resolved quickly, I think it would be a good self-contained task for someone to get started with python-tuf development. AFAICS what’s missing is:

  • apply/revise patch from above
  • adopt MetadataDeserializer accordingly (beware of type check case handling and cyclic-imports!)
  • add a test
1reaction
jkucommented, Nov 9, 2021

so it should mean Metadata is a Generic, and it’s generic over the type T – this is often used to mean that the Generic is container for type T, as it is here (even if our container is a bit unique in that there is always one and only one T in Metadata).

Read more comments on GitHub >

github_iconTop Results From Across the Web

A tour of the Dart language
This page shows you how to use each major Dart feature, from variables and operators to classes and libraries, with the assumption that...
Read more >
Static factory pattern with inheritance and type hints
I want both of them to use the static factory pattern (or "named constructors"). I've seen some examples of that pattern, but none...
Read more >
How do I pick a service implementation by context?
Option 4: Use Metadata ... We just use the correct base class in the constructor: ... You can associate metadata with registrations directly:....
Read more >
What's new in .NET Framework - Microsoft Learn
Windows Forms is a thin managed wrapper around the Windows API, ... the client retrieves parameter metadata from the server only once.
Read more >
EclipseLink‎ | Development‎ | JPA 2.0 - Eclipsepedia
1) The Metamodel API exposes the entity annotation API and the XML mapping API as one unified "metadata" type-safe API. 2) The Metamodel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found