Improve WrappedResponse compatibility and safe repr#20
Open
Conversation
### Motivation - Make migration from the legacy erpbrasil.edoc API smoother by exposing familiar attributes on the new `WrappedResponse` while allowing cleaner future names. - Provide a `text` accessor on wrapped HTTP responses so callers that expect `requests.Response.text` keep working. - Prevent `__repr__` from failing or showing uninitialized state when `uf` is omitted by ensuring it is initialized. ### Description - Replace direct `Logger` instantiation with `logging.getLogger(__name__)` for idiomatic module logger usage. - Add `WrappedHTTPResponse.text` property that decodes `content` to a string with replacement on errors to mirror `requests.Response.text`. - Add alias properties on `WrappedResponse`: `request_obj`, `request_xml`, `response_obj`, and `response`, which return the existing legacy attributes (`envio_raiz`, `envio_xml`, `resposta`, `retorno`) to support a progressive API rename. - Initialize `self.uf` to `None` in `FiscalClient.__init__` so `repr(client)` is stable when `uf` is not provided. - Add two unit tests in `tests/test_fiscal_client.py`: `test_wrapped_response_aliases` to validate aliases and `test_repr_with_no_uf` to validate `repr` behavior. ### Testing - Added unit tests: `test_wrapped_response_aliases` and `test_repr_with_no_uf` in `tests/test_fiscal_client.py`. - Ran `python -m compileall brazil_fiscal_client tests`, which succeeded. - Ran `pytest -q`, which failed during collection due to a missing external dependency in the environment: `ModuleNotFoundError: No module named 'nfelib'`, so full test execution could not be completed here.
…razil-fiscal-client
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
WrappedResponsewhile allowing cleaner future names.textaccessor on wrapped HTTP responses so callers that expectrequests.Response.textkeep working.__repr__from failing or showing uninitialized state whenufis omitted by ensuring it is initialized.Description
Loggerinstantiation withlogging.getLogger(__name__)for idiomatic module logger usage.WrappedHTTPResponse.textproperty that decodescontentto a string with replacement on errors to mirrorrequests.Response.text.WrappedResponse:request_obj,request_xml,response_obj, andresponse, which return the existing legacy attributes (envio_raiz,envio_xml,resposta,retorno) to support a progressive API rename.self.uftoNoneinFiscalClient.__init__sorepr(client)is stable whenufis not provided.tests/test_fiscal_client.py:test_wrapped_response_aliasesto validate aliases andtest_repr_with_no_ufto validatereprbehavior.Testing
test_wrapped_response_aliasesandtest_repr_with_no_ufintests/test_fiscal_client.py.python -m compileall brazil_fiscal_client tests, which succeeded.pytest -q, which failed during collection due to a missing external dependency in the environment:ModuleNotFoundError: No module named 'nfelib', so full test execution could not be completed here.Codex Task