-
Notifications
You must be signed in to change notification settings - Fork 9
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
Upgrade to pydantic v2 #141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
pycfmodel/model/generic.py
Outdated
ResolvableDateOrList, | ||
ResolvableDatetimeOrList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes the order due to the new lax config of pydantic. Date can be parsed inside a Datetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to add a comment mentioning this as it won't be obvious going forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
@@ -23,12 +23,6 @@ class Resource(CustomModel): | |||
UpdatePolicy: Optional[Dict] = None | |||
UpdateReplacePolicy: Optional[ResolvableStr] = None | |||
|
|||
@validator("Type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been replaced by a Discriminated Union
|
||
|
||
class GenericResource(Resource): | ||
"""This class is used for all resource types that don't have a dedicated class.""" | ||
|
||
ALLOW_EXISTING_TYPES: ClassVar[bool] = True | ||
Type: str | ||
Type: Optional[str] = None # Optional to handle cases like "AWS::CloudFormation::Authentication" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ignaciobolonio Review this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any issue with this as long as it has retrocompatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a LOT of changes but it follows a similar way to my attempt here https://github.com/Skyscanner/pycfmodel/tree/update_pydantic_v2 It is amazing work Oscar, great contribution
|
||
|
||
class GenericResource(Resource): | ||
"""This class is used for all resource types that don't have a dedicated class.""" | ||
|
||
ALLOW_EXISTING_TYPES: ClassVar[bool] = True | ||
Type: str | ||
Type: Optional[str] = None # Optional to handle cases like "AWS::CloudFormation::Authentication" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any issue with this as long as it has retrocompatibility
pycfmodel/action_expander.py
Outdated
@@ -34,9 +34,9 @@ def _expand_actions(actions: Union[str, List[str]], not_action=False) -> List[st | |||
def expand_actions(obj): | |||
if isinstance(obj, dict): | |||
for key, value in obj.items(): | |||
if key == "Action": | |||
if key == "Action" and value is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if key == "Action" and value is not None: | |
if value is None: | |
continue # or obj[key] = None | |
elif key == "Action": |
Otherwise we'll end up recursively calling expand actions. I'm not sure if that's what we want, but in any case it should change the current behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
from pycfmodel.model.base import FunctionDict | ||
|
||
|
||
class LooseIPv4Network(_BaseNetwork): | ||
class LooseIPv4Network: | ||
__slots__ = () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we want slots here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to make it more efficient, we don't want to store anything in memory
pycfmodel/model/types.py
Outdated
@@ -78,15 +135,19 @@ def validate(cls, value: Any) -> bool: | |||
|
|||
ResolvableIPv4Network = Resolvable[LooseIPv4Network] | |||
ResolvableIPv6Network = Resolvable[LooseIPv6Network] | |||
ResolvableIPvXNetwork = Annotated[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResolvableIPvXNetwork = Annotated[ | |
ResolvableIPNetwork = Annotated[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
setup.py
Outdated
@@ -28,7 +28,7 @@ | |||
|
|||
setup( | |||
name="pycfmodel", | |||
version="0.22.0", | |||
version="0.23.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a major here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, and updated to 1.0.0
* Add boolean coercion to string * Minor fixes * Minor fixes * Update cf actions
Co-authored-by: Jordi Soucheiron <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work!
No description provided.