-
Notifications
You must be signed in to change notification settings - Fork 143
Use keyword arguments for model classes #189
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
Merged
horgh
merged 9 commits into
main
from
greg/eng-1088-implement-minfraud-python-improvements-in-geoip2
Jan 28, 2025
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5575bd
Join some split strings
oschwald 8d366fd
Whitespace improvements
oschwald 069704a
Replace raw attribute with to_dict method
oschwald 79ca31d
Make geoip2.mixins geoip2._internal
oschwald c84b047
Require record arguments to be keyword arguments
oschwald 4518919
Convert model classes to use keyword arguments
oschwald 0e8790c
Make ip_address property more similar to network
oschwald dedb92c
Add empty permission block
oschwald 574f026
Fix typos
oschwald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ on: | |
| schedule: | ||
| - cron: '0 11 * * 2' | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| CodeQL-Build: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ on: | |
| types: | ||
| - published | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build source distribution | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ on: | |
| schedule: | ||
| - cron: '3 15 * * SUN' | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ on: | |
| pull_request: | ||
| branches: ["**"] | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| zizmor: | ||
| name: zizmor latest via PyPI | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """This package contains internal utilities""" | ||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| from abc import ABCMeta | ||
| from typing import Any | ||
|
|
||
|
|
||
| class Model(metaclass=ABCMeta): | ||
| """Shared methods for MaxMind model classes""" | ||
|
|
||
| def __eq__(self, other: Any) -> bool: | ||
| return isinstance(other, self.__class__) and self.to_dict() == other.to_dict() | ||
|
|
||
| def __ne__(self, other): | ||
| return not self.__eq__(other) | ||
|
|
||
| # pylint: disable=too-many-branches | ||
| def to_dict(self): | ||
| """Returns a dict of the object suitable for serialization""" | ||
| result = {} | ||
| for key, value in self.__dict__.items(): | ||
| if key.startswith("_"): | ||
| continue | ||
| if hasattr(value, "to_dict") and callable(value.to_dict): | ||
| if d := value.to_dict(): | ||
| result[key] = d | ||
| elif isinstance(value, (list, tuple)): | ||
| ls = [] | ||
| for e in value: | ||
| if hasattr(e, "to_dict") and callable(e.to_dict): | ||
| if e := e.to_dict(): | ||
| ls.append(e) | ||
| elif e is not None: | ||
| ls.append(e) | ||
| if ls: | ||
| result[key] = ls | ||
| # We only have dicts of strings currently. Do not bother with | ||
| # the general case. | ||
| elif isinstance(value, dict): | ||
| if value: | ||
| result[key] = value | ||
| elif value is not None and value is not False: | ||
| result[key] = value | ||
|
|
||
| # network and ip_address properties for performance reasons | ||
| # pylint: disable=no-member | ||
| if hasattr(self, "ip_address") and self.ip_address is not None: | ||
| result["ip_address"] = str(self.ip_address) | ||
| if hasattr(self, "network") and self.network is not None: | ||
| result["network"] = str(self.network) | ||
|
|
||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.