Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Add support for regex Patterns #439

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

aneeshusa
Copy link
Contributor

No description provided.

@aneeshusa
Copy link
Contributor Author

@ltworf I recently discovered typedload and find it a breath of fresh air compared to other libraries that don't work with e.g. standard dataclasses - thank you for making it!
I have been adopting it in my work codebases and noticed Patterns were not supported, hence the PR.
I looked at the CONTRIBUTING.md but didn't see any mention of updating the version or changelog - is that something I should do in the PR?

I see merging is blocked on getting the commit signed, I will look into how to set that up for this contribution.

@ltworf
Copy link
Owner

ltworf commented Jan 2, 2024

Hello, thanks for the contribution.

I'm on vacation now, I'll have a look at it next week I think.

Copy link
Owner

@ltworf ltworf left a comment

Choose a reason for hiding this comment

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

Hello,

overall it is good. I commented on some things that need fixing before this can be merged.

For the future, I'd prefer separate commits for typecheck, dumper, loader, and tests… or maybe the tests can be added in the same commit of the relative function.

Yes, you should add an entry in the changelog, and update to https://github.com/ltworf/typedload/blob/master/docs/supported_types.md is needed as well.

Don't worry about the signature, I can override the setting if you've never used it before.

typedload/typechecks.py Show resolved Hide resolved
typedload/dataloader.py Outdated Show resolved Hide resolved
(lambda type_: type_ in self.strconstructed, _strconstructload),
(lambda type_: type_ == datetime.timedelta, _timedeltaload),
Copy link
Owner

Choose a reason for hiding this comment

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

why did you move this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was a remnant of earlier debugging but it should not be needed, undid this, thanks for pointing it out.

tests/test_dataloader.py Show resolved Hide resolved
tests/test_dataloader.py Show resolved Hide resolved
@aneeshusa aneeshusa force-pushed the add-support-for-regex-patterns branch from 1de8334 to 04a9977 Compare January 8, 2024 16:30
Copy link
Contributor Author

@aneeshusa aneeshusa left a comment

Choose a reason for hiding this comment

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

I hope you had a relaxing vacation! Thank you for the review.

Good point that this needs error handling, added that with tests. Updated the two docs you mentioned as well.

I addressed all the feedback in a new fixup-style commit; happy to squash it into the previous commit or squash into 3 commits (loader changes + tests, dumper changes + tests, docs changes), let me know what you prefer.

I would appreciate if you could override the setting about the signatures.

Let me know if there is anything I missed!

tests/test_dataloader.py Show resolved Hide resolved
(lambda type_: type_ in self.strconstructed, _strconstructload),
(lambda type_: type_ == datetime.timedelta, _timedeltaload),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was a remnant of earlier debugging but it should not be needed, undid this, thanks for pointing it out.

@ltworf ltworf merged commit e773769 into ltworf:master Jan 8, 2024
6 checks passed
@ltworf
Copy link
Owner

ltworf commented Jan 8, 2024

Ok, merged.

Let me know if you'd like to contribute more, then I could add you to the project so you can do PR directly.

Thanks :)

@aneeshusa
Copy link
Contributor Author

Thanks! I haven't run into any other meaningful pieces to contribute yet but will let you know if I do.

That being said, one minor note, I just noticed a few more places that may need to be updated to mention the new support from this PR:

  • List of supported types in the README: https://github.com/ltworf/typedload/blob/master/README.md#supported-types
  • List of supported types in package docstring:
    Supported datatypes
    ===================
    There is support for:
    * Basic python types (int, str, bool, float, NoneType)
    * NamedTuple
    * Enum
    * Optional[SomeType]
    * List[SomeType]
    * Dict[TypeA, TypeB]
    * Tuple[TypeA, TypeB, TypeC]
    * Tuple[SomeType, ...]
    * Set[SomeType]
    * Union[TypeA, TypeB]
    * ForwardRef
    * Literal
    * Dataclass
    * attrs
    * TypedDict
    * datetime
    * Path
    * IPv4Address, IPv6Address

I wonder if we need to have the list of supported types in 3 places and if we could consolidate some of those? In any case happy to make a PR tomorrow with whatever your preference is.

@ltworf
Copy link
Owner

ltworf commented Jan 9, 2024

Ah yes those should be updated as well, you want to make another pr for that?

Consolidation would be good, but they appear in different spots.

The readme is the "homepage" and also the text that goes on pypi, the docstring is converted on the website but also appears with help() in python, and the supported_types i guess is the more specific documentation with all the details. I don't have any good solution to merge the 3 without making the readme overly verbose.

@aneeshusa
Copy link
Contributor Author

Fair enough - made #441 to update the docs.

@aneeshusa aneeshusa deleted the add-support-for-regex-patterns branch January 10, 2024 07:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants