This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add an explicit test for `get_type_hints` for a class field with `None` default
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, gvanrossum, kj, miss-islington, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-11 15:12 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30535 merged sobolevn, 2022-01-11 15:18
PR 30567 merged miss-islington, 2022-01-12 23:35
PR 30568 merged miss-islington, 2022-01-12 23:36
Messages (9)
msg410307 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-11 15:12
Right now this corner case is not tested:

```python
class Some:
    x: int = None

import typing
assert typing.get_type_hints(Some) == {'x': int}
```

Notice that we don't add implicit `Optional` type to `x`. This is different for function arguments that will have `Optional` added.

I think it is a good idea to add a test for this. Espeically given that we can change function's behavior.

Context:
- https://bugs.python.org/issue46195
- https://github.com/python/cpython/pull/30304
msg410308 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-11 15:13
I will send a PR today :)
msg410443 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-01-12 23:36
New changeset 1de60155d5d01be2924e72fb68dd13d4fd00acd7 by Nikita Sobolev in branch 'main':
bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)
https://github.com/python/cpython/commit/1de60155d5d01be2924e72fb68dd13d4fd00acd7
msg410449 - (view) Author: miss-islington (miss-islington) Date: 2022-01-13 01:45
New changeset a468866a67d83a24e3a3c3a0070129773d28bbd9 by Miss Islington (bot) in branch '3.10':
bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)
https://github.com/python/cpython/commit/a468866a67d83a24e3a3c3a0070129773d28bbd9
msg410450 - (view) Author: miss-islington (miss-islington) Date: 2022-01-13 01:46
New changeset d9101c4e49dc29f21319493818130ad5468402a2 by Miss Islington (bot) in branch '3.9':
bpo-46345: Add a test case for implicit `Optional` class attribute (GH-30535)
https://github.com/python/cpython/commit/d9101c4e49dc29f21319493818130ad5468402a2
msg410457 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2022-01-13 03:11
When I take a look at previous PRs, most of adding test cases were not backported.
The backported cases were triggered by bug issues.
But let's pass this case as an exceptional case.
msg410462 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-01-13 05:43
Wasn’t the fix for it also backported?

(Weird that the test wasn’t part of the fix.)
msg410463 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2022-01-13 05:47
@gvanrossum

Ah okay, Looks like bpo-46195 is the root of this issue.
In this case, backporting is reasonable.
msg410464 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2022-01-13 05:58
@sobolevn

Do you want to close it?
Cleaning up the issue is one of the duties of triage members :)
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90503
2022-01-14 12:09:37sobolevnsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-13 05:58:05corona10setmessages: + msg410464
2022-01-13 05:48:01corona10setversions: + Python 3.9, Python 3.10
2022-01-13 05:47:55corona10setmessages: + msg410463
2022-01-13 05:43:00gvanrossumsetmessages: + msg410462
2022-01-13 03:11:20corona10setnosy: + corona10
messages: + msg410457
2022-01-13 01:46:38miss-islingtonsetmessages: + msg410450
2022-01-13 01:45:57miss-islingtonsetmessages: + msg410449
2022-01-12 23:36:01gvanrossumsetmessages: + msg410443
2022-01-12 23:36:00miss-islingtonsetpull_requests: + pull_request28771
2022-01-12 23:35:56miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28770
2022-01-12 22:09:15AlexWaygoodsettype: behavior
components: + Tests, - Library (Lib)
2022-01-12 22:08:44AlexWaygoodsetnosy: + gvanrossum, kj
2022-01-11 15:18:06sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28736
2022-01-11 15:13:28sobolevnsetmessages: + msg410308
2022-01-11 15:12:50sobolevncreate