[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread Łukasz Langa

Change by Łukasz Langa :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 66d7a5d58a88bce312bc4668f2cc54c9488c5bd8 by Łukasz Langa (Miss 
Islington (bot)) in branch '3.7':
bpo-34776: Fix dataclasses to support __future__ "annotations" mode (GH-9518) 
(#17532)
https://github.com/python/cpython/commit/66d7a5d58a88bce312bc4668f2cc54c9488c5bd8


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 0d57db27f2c563b6433a220b646b50bdeff8a1f2 by Łukasz Langa (Miss 
Islington (bot)) in branch '3.8':
bpo-34776: Fix dataclasses to support __future__ "annotations" mode (GH-9518) 
(#17531)
https://github.com/python/cpython/commit/0d57db27f2c563b6433a220b646b50bdeff8a1f2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread miss-islington


Change by miss-islington :


--
pull_requests: +17010
pull_request: https://github.com/python/cpython/pull/17532

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread miss-islington


Change by miss-islington :


--
pull_requests: +17009
pull_request: https://github.com/python/cpython/pull/17531

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-09 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset d219cc4180e7589807ebbef7421879f095e72a98 by Łukasz Langa (Yury 
Selivanov) in branch 'master':
bpo-34776: Fix dataclasses to support __future__ "annotations" mode (#9518)
https://github.com/python/cpython/commit/d219cc4180e7589807ebbef7421879f095e72a98


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-12-07 Thread Ned Deily


Ned Deily  added the comment:

>  I'll elevate the status so that I don't forget before 3.8.1.

Ping, 3.8.1 cutoff is coming up very soon.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-10-23 Thread Yury Selivanov


Yury Selivanov  added the comment:

> Yury: I'm okay with merging. If I recall, you were going to add a comment or 
> two about the approach (a closure, if I remember correctly).

Sure, I'll rebase and add a comment in a couple of days.  I'll elevate the 
status so that I don't forget before 3.8.1

--
assignee: eric.smith -> yselivanov
priority:  -> deferred blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-10-23 Thread Eric V. Smith


Eric V. Smith  added the comment:

Yury: I'm okay with merging. If I recall, you were going to add a comment or 
two about the approach (a closure, if I remember correctly).

I think we should backport to 3.8 and 3.7: it's a bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-10-23 Thread Yury Selivanov


Yury Selivanov  added the comment:

FWIW we discussed my patch with Eric at PyCon 2019 and I think he had no issues 
with it.  Eric, can I merge it?  Should we backport to 3.8?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-10-23 Thread Gregory P. Smith


Change by Gregory P. Smith :


--
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-10-23 Thread David Hagen


David Hagen  added the comment:

This PR has been sitting for a while. Any chance we can bring it over the 
finish line?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-03-05 Thread Eric V. Smith


Eric V. Smith  added the comment:

I'm finally getting time to look at this. I'll see what I can do.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2019-03-02 Thread Vlad Shcherbina


Vlad Shcherbina  added the comment:

Any chance this could get into 3.7.3?

--
nosy: +vlad

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-10-04 Thread Yury Selivanov


Yury Selivanov  added the comment:

> Please note that postponed annotations only reveal a problem that we already 
> had if anybody used a string forward reference:

Yeah, makes sense. It's cool that the PR fixes string forward references as 
well.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-10-04 Thread Łukasz Langa

Łukasz Langa  added the comment:

Yury, thanks for your patch. I'll review it soon.

Please note that postponed annotations only reveal a problem that we already 
had if anybody used a string forward reference:

>>> from dataclasses import dataclass
>>> from typing import get_type_hints
>>> class C:
...   pass
...
>>> @dataclass
... class D:
...   c: C
...
>>> @dataclass
... class E:
...   c: "C"
...
>>> get_type_hints(C.__init__)
{}
>>> get_type_hints(D.__init__)
{'c': , 'return': }
>>> get_type_hints(E.__init__)
Traceback (most recent call last):
...
NameError: name 'C' is not defined

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-28 Thread Stefan Behnel


Change by Stefan Behnel :


--
nosy: +scoder

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-27 Thread INADA Naoki


Change by INADA Naoki :


--
nosy: +inada.naoki

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-27 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


--
nosy: +levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-24 Thread Gregory P. Smith


Gregory P. Smith  added the comment:

fwiw, agreed that this should wait for 3.7.2.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-24 Thread Gregory P. Smith


Change by Gregory P. Smith :


--
nosy: +gregory.p.smith
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-24 Thread Yury Selivanov


Yury Selivanov  added the comment:

NP, Eric, take your time. I agree that the PR isn't simple and needs a very 
careful review.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

Unfortunately, I'm not going to be able to give this the attention it deserves 
before the 3.7.1 cutoff. The changes are sufficiently tricky that I want to 
make sure I think through the issue in the appropriate detail.

Ned: I've made it not a release blocker. Please remove yourself as nosy if you 
don't care about this issue. I don't plan on making it a release blocker again, 
I just did that because it was so near the deadline.

Yury: Sorry for not being able to get delve in to it sufficiently. Thanks for 
your work on it.

I should be able to review this in the next few days, so we can get this in to 
3.7.2.

--
priority: release blocker -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-24 Thread Eric V. Smith


Eric V. Smith  added the comment:

Ned: I'm marking this as a release blocker because I'd like to get it in 3.7.1. 
If I can't do that in the next 5 hours or so, I'll remove the release blocker 
tag.

--
assignee:  -> eric.smith
nosy: +ned.deily
priority: normal -> release blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-23 Thread Yury Selivanov


Yury Selivanov  added the comment:

And FWIF I don't think we need to use lambdas for annotations to solve issues 
like this one.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-23 Thread Yury Selivanov


Yury Selivanov  added the comment:

> See this for Yury's self-described "hack-ish fix we can use" until we do 
> something better:

Actually, I think I found a better solution that doesn't require any changes to 
anything besides dataclasses.

Currently, dataclasses uses 'exec()' function to dynamically create methods 
like '__init__'.  The generated code for '__init__' needs to access MISSING and 
_HAS_DEFAULT_FACTORY constants from the dataclasses module.  To do that, we 
compile the code with 'exec()' with globals set to a dict with {MISSING, 
_HAS_DEFAULT_FACTORY} keys in it.  This does the trick, but 
'__init__.__globals__' ends up pointing to that custom dict, instead of 
pointing to the module's dict.

The other way around is to use a closure around __init__ to inject MISSING and 
_HAS_DEFAULT_FACTORY values *and* to compile the code in a proper __dict__ of 
the module the dataclass was defined in.  Please take a look at the PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-23 Thread Yury Selivanov


Change by Yury Selivanov :


--
keywords: +patch
pull_requests: +8923
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-23 Thread Eric V. Smith


Eric V. Smith  added the comment:

[Adding to nosy people who were on the original email]

Copying (part of) my response from the email thread:

These work:
print(get_type_hints(Bar.__init__, globals()))
print(get_type_hints(Bar.__init__, Bar.__module__))

But I agree that maybe doing something with dataclasses to address this would 
be good. Especially as the first one requires being in the same module as Foo.

See this for Yury's self-described "hack-ish fix we can use" until we do 
something better:

https://gist.github.com/1st1/37fdd3cc84cd65b9af3471b935b722df

--
nosy: +eric.smith, gvanrossum, ivan, lukasz.langa, yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34776] Postponed annotations break inspection of dataclasses

2018-09-23 Thread David Hagen


New submission from David Hagen :

The new postponed annotations have an unexpected interaction with dataclasses. 
Namely, you cannot get the type hints of any of the data classes methods.

For example, I have some code that inspects the type parameters of a class's 
`__init__` method. (The real use case is to provide a default serializer for 
the class, but that is not important here.)  

```
from dataclasses import dataclass
from typing import get_type_hints

class Foo:
pass

@dataclass
class Bar:
foo: Foo

print(get_type_hints(Bar.__init__))
```

In Python 3.6 and 3.7, this does what is expected; it prints `{'foo': , 'return': }`.

However, if in Python 3.7, I add `from __future__ import annotations`, then 
this fails with an error:

```
NameError: name 'Foo' is not defined
```

I know why this is happening. The `__init__` method is defined in the 
`dataclasses` module which does not have the `Foo` object in its environment, 
and the `Foo` annotation is being passed to `dataclass` and attached to 
`__init__` as the string `"Foo"` rather than as the original object `Foo`, but 
`get_type_hints` for the new annotations only does a name lookup in the module 
where `__init__` is defined not where the annotation is defined.

I know that the use of lambdas to implement PEP 563 was rejected for 
performance reasons. I could be wrong, but I think this was motivated by 
variable annotations because the lambda would have to be constructed each time 
the function body ran. I was wondering if I could motivate storing the 
annotations as lambdas in class bodies and function signatures, in which the 
environment is already being captured and is code that usually only runs once.

Original mailing list discussion: 
https://mail.python.org/pipermail/python-dev/2018-September/155289.html

--
messages: 326148
nosy: drhagen
priority: normal
severity: normal
status: open
title: Postponed annotations break inspection of dataclasses
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com