This pull request improves Response and PaginatedResponse in various ways.
New features:
To facilitate testing and local development, Response objects are now fully typed through the attribute syntax. (This update is a follow-up of #479, where civis.APIClient has since been fully typed for the API endpoints and methods.) Typing response. in an IDE such as VS Code now triggers autocomplete suggestions for available attributes. In testing, static type checkers such as mypy can now catch possible code issues based on response attribute access. See the screen capture below.
For simpler code, both Response and PaginatedResponse are now directly available under the civis namespace. This means that civis.Response and civis.PaginatedResponse (in addition to the existing civis.response.Response and civis.response.PaginatedResponse) are now valid, and that for imports, the statement from civis import Response, PaginatedResponse is also valid (in addition to the existing from civis.response import Response, PaginatedResponse).
Changed:
For an API call from civis.APIClient that returns a PaginatedResponse object (with iterator=True), the user-specified kwarg limit is now honored to facilitate speeding up the pagination.
Bug fixes:
The repr form of Response objects now looks like the dict-based Response({‘spam’: 123}) instead of the dataclass-based Response(spam=123), because response object keys can be invalid Python identifiers (e.g., containing dashes or forward slashes, or even just an empty string).
In Response object instantiation, object keys that originate from environment variables (e.g., under environmentVariables in the /services endpoint) are now preserved for their (customarily upper-) case even in the default snake-case setting.
In Response object instantiation, an API response that represents a JSONValue object now has its value attribute unmodified as the Python object representation of the deserialized JSON form (as opposed to being converted to a Response-based form).
VS Code screen capture for the attribute knowledge of an API response object:
[x] (For Civis employees only) Reference to a relevant ticket in the pull request title
[x] Changelog entry added to CHANGELOG.md at the repo's root level
[x] Description of change in the pull request description
[x] If applicable, unit tests have been added and/or updated
This pull request improves
Response
andPaginatedResponse
in various ways.New features:
Response
objects are now fully typed through the attribute syntax. (This update is a follow-up of #479, wherecivis.APIClient
has since been fully typed for the API endpoints and methods.) Typingresponse.
in an IDE such as VS Code now triggers autocomplete suggestions for available attributes. In testing, static type checkers such asmypy
can now catch possible code issues based on response attribute access. See the screen capture below.Response
andPaginatedResponse
are now directly available under thecivis
namespace. This means thatcivis.Response
andcivis.PaginatedResponse
(in addition to the existingcivis.response.Response
andcivis.response.PaginatedResponse
) are now valid, and that for imports, the statementfrom civis import Response, PaginatedResponse
is also valid (in addition to the existingfrom civis.response import Response, PaginatedResponse
).Changed:
civis.APIClient
that returns aPaginatedResponse
object (withiterator=True
), the user-specified kwarglimit
is now honored to facilitate speeding up the pagination.Bug fixes:
Response
objects now looks like the dict-basedResponse({‘spam’: 123})
instead of the dataclass-basedResponse(spam=123)
, because response object keys can be invalid Python identifiers (e.g., containing dashes or forward slashes, or even just an empty string).Response
object instantiation, object keys that originate from environment variables (e.g., underenvironmentVariables
in the/services
endpoint) are now preserved for their (customarily upper-) case even in the default snake-case setting.Response
object instantiation, an API response that represents a JSONValue object now has itsvalue
attribute unmodified as the Python object representation of the deserialized JSON form (as opposed to being converted to aResponse
-based form).VS Code screen capture for the attribute knowledge of an API response object:
CHANGELOG.md
at the repo's root level