Skip to content

Conversation

@vlaci
Copy link
Contributor

@vlaci vlaci commented Jul 10, 2024

  • It was already interpreted essentially the same way as typing.Any, because of its __getattr__ method
  • Newer versions no longer have the Instance proxy object
  • cstruct().<x> calls are annotated with Any in new versions
  • The actual runtime type will be Structure in newer versions that needs to be changed in logging (not changed for now)

Relates-to: #888

@vlaci vlaci force-pushed the relax-dissect-cstruct-annotation branch 2 times, most recently from c13c28e to 031fa78 Compare July 10, 2024 20:42
@vlaci vlaci changed the title chore(dissect.cstruct): Git rid of Instance type annotation chore(dissect.cstruct): Get rid of Instance type annotation Jul 10, 2024
@e3krisztian e3krisztian self-requested a review July 22, 2024 15:51
@e3krisztian
Copy link
Contributor

I did not like the Instance type annotations and celebrate its demise, as they were too generic to be meaningful, and what else do we have as values as type instances?

However instead of going explicitly Any (which is not really useful as a type annotation either for automated check or for human readers), I would prefer introducing a specific type alias for Any, by the name Structure or CStruct. Although it would not be much help as a machine checkable type annotation, but it would at least signal a type for the human reader.
After upgrading dissect.cstruct, the new Structure could be aliased/used instead.

@vlaci
Copy link
Contributor Author

vlaci commented Jul 22, 2024

Unfortunately this Structure is sprinkled with so heavy metaclass magic1, that even its __mro__ is unavailable as they are overwriting the instance dict directly... Fortunately, the isinstance(..., Structure) check will work for logging, but we won't be able to use it for type hints, as the generated fields are absent on the class definition.

Type-hinting with a custom Any type doesn't really add anything to it besides requiring extra imports for type annotations to work. I can add it though if you'd think it'd add any value

Footnotes

  1. https://github.com/fox-it/dissect.cstruct/blob/7f6a584f77d48e8cce0ca11fd129b6f2a27e82a1/dissect/cstruct/types/structure.py#L367

- It was already interpreted essentially the same way as `typing.Any`,
  because of its `__getattr__` method
- Newer versions no longer have the `Instance` proxy object
- `cstruct().<x>` calls are annotated with `Any` in new versions
- The actual runtime type will be `Structure` in newer versions that
  needs to be changed in `logging` (not changed for now)

Relates-to: #888
@vlaci vlaci force-pushed the relax-dissect-cstruct-annotation branch from 031fa78 to 919270a Compare July 23, 2024 13:22
@vlaci vlaci merged commit eb8b1b5 into main Jul 23, 2024
@vlaci vlaci deleted the relax-dissect-cstruct-annotation branch July 23, 2024 13:32
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.

3 participants