Skip to content

AttributeDict typing and constructor updates #3105

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

Closed
pacrob opened this issue Sep 21, 2023 · 3 comments
Closed

AttributeDict typing and constructor updates #3105

pacrob opened this issue Sep 21, 2023 · 3 comments
Labels
Pending Clarification v7 breaking changes considered for v7

Comments

@pacrob
Copy link
Contributor

pacrob commented Sep 21, 2023

AttributeDict and it's parent classes use Mapping[TKey, TValue] for typing, but in practice they often have multiple types in a single structure, at least in the values (strings, ints, hexbytes, etc.)

Consider changing the type, either by being more specific, or opening it to Any, as a user could theoretically turn any mapping into an AttributeDict.

Also, since an AttributeDict is expected to be a hashable datastructure, consider doing recursive tupleization/checking for unhashable types at the time of creation, instead of only when trying to hash it.

@reedsa reedsa added the v7 breaking changes considered for v7 label Nov 8, 2023
@fselmo
Copy link
Collaborator

fselmo commented Apr 16, 2024

I took a quick peek at this. The way it's currently set up allows the user to define what they want it to be. For example,

# this still works with `Any`
some_arg: AttributeDict[str, Any]

# but if we want to narrow the typing more, we can
some_arg: AttributeDict[bytes, bytes]

Unless I'm missing something, I think this is good the way it is. Thoughts?

@fselmo
Copy link
Collaborator

fselmo commented Apr 17, 2024

Also, since an AttributeDict is expected to be a hashable datastructure, consider doing recursive tupleization/checking for unhashable types at the time of creation, instead of only when trying to hash it.

I guess I didn't address this part but I feel like we shouldn't change the types that aren't assigned internally, especially if it is indeed declared at the type-hinting level. I'd rather only use it when hashing, as we currently do.

@pacrob
Copy link
Contributor Author

pacrob commented Apr 24, 2024

Yep, no issue leaving as-is. I don't think I understood the creation process properly when I opened the issue.

@pacrob pacrob closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending Clarification v7 breaking changes considered for v7
Projects
None yet
Development

No branches or pull requests

3 participants