Repository: aio-libs/aiohttp
Pull request: Added properties of default ClientSession params to ClientSession class
## What do these changes do?

Added properties of default ClientSession params to ClientSession class so it is available for introspection now

## Are there changes in behavior for the user?

Users can now see which default parameters were initialized with ClientSession

## Related issue number

This commit fixes  #3882

## Checklist

- [x] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names. 
- [x] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
  * if you don't have an `issue_id` change it to the pr id after creating the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
    * `.misc`: A ticket has been closed, but it is not of interest to users.
  * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."


Problem statement:
Expose ClientSession defaults such as headers and auth for introspection
## Long story short

Too many attributes of ClientSession are private without an explicit need to. The following constructor arguments can never be accessed after creating a session:

- `headers`
- `skip_auto_headers`
- `auth`
- `json_serialize`
- ~`request_class`~
- ~`response_class`~
- ~`ws_response_class`~
- `connector_owner`
- `raise_for_status`
- `timeout`
- `auto_decompress`
- `trust_env`
- `trace_configs`

## Expected behaviour

I want to be able to create a new session based on an existing session, only tweaking some aspects. Without access to these attributes, you can't properly create a new session instance with only some aspects replaced.

## Actual behaviour

You have to access API private attribute to get at this information, making it much harder than necessary to create an updated wrapper as session needs change.

For example, I'm currently implementing an OAuth 2.0 authentication handler, which automatically fetches an authentication token if required for the current request, transparently. We create a client session in a different part of the app, shared between a group of objects, some of which need to dynamically switch to support OAuth 2.0. 

Rather than have to create a new session for each of object regardless of OAuth needs (preventing connection re-use between some of these objects where the same server is involved) or having to introspect every request to see if OAuth applies to this specific request, I want to create a new session only when OAuth is actually needed, reusing the same connection pool, if and when OAuth is needed. But this requires knowing the headers, timeouts and trace config on the session used so far.

Hints from issue discussion:
PR for providing properties for them is welcome, except `request_class`, `response_class`, and `ws_response_class`. 

These three arguments will be removed soon.
What was the reason to hide them on first place? Perhaps exporting the API is not too cool. I have never needed that by making sessions persistent in one place and reusing whatever common bits I needed there.

Just asking, because not having them publicly available might have been done on purpose.
The reason for not exposing API was: nobody asked.
I had doubts what parameters should be exposed but now I see no objections.
#4193 adds a timeout property. 
Looking for a champion for other names
No need to expose all properties at once, multiple PRs are acceptable.

Commit message: dix mypy

Patch to review:
diff --git a/CHANGES/3882.feature b/CHANGES/3882.feature
new file mode 100644
index 00000000000..0337fcdcd33
--- /dev/null
+++ b/CHANGES/3882.feature
@@ -0,0 +1 @@
+Added properties of default ClientSession params to ClientSession class so it is available for introspection
diff --git a/aiohttp/client.py b/aiohttp/client.py
index d7061215dc8..7a4ab80ac43 100644
--- a/aiohttp/client.py
+++ b/aiohttp/client.py
@@ -14,6 +14,7 @@
     Awaitable,
     Callable,
     Coroutine,
+    FrozenSet,
     Generator,
     Generic,
     Iterable,
@@ -918,6 +919,60 @@ def timeout(self) -> Union[object, ClientTimeout]:
         """Timeout for the session."""
         return self._timeout
 
+    @property
+    def default_headers(self) -> 'CIMultiDict[str]':
+        """The default headers of the client session."""
+        return self._default_headers
+
+    @property
+    def skip_auto_headers(self) -> FrozenSet[istr]:
+        """Headers for which autogeneration should be skipped"""
+        return self._skip_auto_headers
+
+    @property
+    def auth(self) -> Optional[BasicAuth]:
+        """An object that represents HTTP Basic Authorization"""
+        return self._default_auth
+
+    @property
+    def json_serialize(self) -> JSONEncoder:
+        """Json serializer callable"""
+        return self._json_serialize
+
+    @property
+    def connector_owner(self) -> bool:
+        """Should connector be closed on session closing"""
+        return self._connector_owner
+
+    @property
+    def raise_for_status(
+        self
+    ) -> Union[bool, Callable[[ClientResponse], Awaitable[None]]]:
+        """
+        Should `ClientResponse.raise_for_status()`
+        be called for each response
+        """
+        return self._raise_for_status
+
+    @property
+    def auto_decompress(self) -> bool:
+        """Should automatically decompress response body"""
+        return self._auto_decompress
+
+    @property
+    def trust_env(self) -> bool:
+        """
+        Should get proxies information
+        from HTTP_PROXY / HTTPS_PROXY environment variables
+        or ~/.netrc file if present
+        """
+        return self._trust_env
+
+    @property
+    def trace_configs(self) -> List[TraceConfig]:
+        """A list of TraceConfig instances used for client tracing"""
+        return self._trace_configs
+
     def detach(self) -> None:
         """Detach connector from session without closing the former.
 
diff --git a/tests/test_client_session.py b/tests/test_client_session.py
index b9e72f1a6ce..82c9379172d 100644
--- a/tests/test_client_session.py
+++ b/tests/test_client_session.py
@@ -70,7 +70,7 @@ async def test_close_coro(create_session) -> None:
 async def test_init_headers_simple_dict(create_session) -> None:
     session = await create_session(headers={"h1": "header1",
                                             "h2": "header2"})
-    assert (sorted(session._default_headers.items()) ==
+    assert (sorted(session.default_headers.items()) ==
             ([("h1", "header1"), ("h2", "header2")]))
 
 
@@ -78,7 +78,7 @@ async def test_init_headers_list_of_tuples(create_session) -> None:
     session = await create_session(headers=[("h1", "header1"),
                                             ("h2", "header2"),
                                             ("h3", "header3")])
-    assert (session._default_headers ==
+    assert (session.default_headers ==
             CIMultiDict([("h1", "header1"),
                          ("h2", "header2"),
                          ("h3", "header3")]))
@@ -88,7 +88,7 @@ async def test_init_headers_MultiDict(create_session) -> None:
     session = await create_session(headers=MultiDict([("h1", "header1"),
                                                       ("h2", "header2"),
                                                       ("h3", "header3")]))
-    assert (session._default_headers ==
+    assert (session.default_headers ==
             CIMultiDict([("H1", "header1"),
                          ("H2", "header2"),
                          ("H3", "header3")]))
@@ -99,7 +99,7 @@ async def test_init_headers_list_of_tuples_with_duplicates(
     session = await create_session(headers=[("h1", "header11"),
                                             ("h2", "header21"),
                                             ("h1", "header12")])
-    assert (session._default_headers ==
+    assert (session.default_headers ==
             CIMultiDict([("H1", "header11"),
                          ("H2", "header21"),
                          ("H1", "header12")]))


Code review comments:
diff_hunk: @@ -918,6 +919,60 @@ def timeout(self) -> Union[object, ClientTimeout]:
         """Timeout for the session."""
         return self._timeout
 
+    @property
+    def default_headers(self) -> 'CIMultiDict[str]':
path: aiohttp/client.py
text: @user1:
```suggestion
    def headers(self) -> 'CIMultiDict[str]':
```
Let's keep property names in sync with constructor parameters