[issue47166] Dataclass transform should ignore TypeAlias variables

2022-04-06 Thread Thomas MK


Thomas MK  added the comment:

There is of course no hard reason for not using the global scope. I just often 
have enums (or other types) that are very closely linked to one class. And it 
makes sense to me then to have a TypeAlias in that class so that I don't have 
to import the enum separately.

For normal classes, the nested TypeAlias works completely fine in the type 
checkers I tested (pyright and mypy). It's just dataclasses that are the 
problem.

But I see now that there is a general wish to keep the implementation of 
dataclass simple, which I can understand.

--

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-31 Thread Eric V. Smith


Eric V. Smith  added the comment:

Same question as Alex: what does the TypeAlias being inside the class offer 
that being at module level doesn't?

--

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-31 Thread Alex Waygood


Alex Waygood  added the comment:

I think implementing this would add complexity to the code in dataclasses.py 
(though Eric's the expert!).

For your use case, is it essential that the type alias declaration be inside 
the class scope? Would it be possible for you to simply have the alias 
declaration in the global scope instead?

--

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-30 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

>From a typing perspective this is reasonable. See this thread about type 
>aliases in class scopes: 
>https://mail.python.org/archives/list/typing-...@python.org/thread/CGOO7GPPECGMLFDUDXSSXTRADI4BXYCS/
> 

However, it's a niche use case and we could decide that we don't want to 
further complicate the annotation parsing in dataclasses.py.

--

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-30 Thread Jelle Zijlstra


Change by Jelle Zijlstra :


--
nosy: +AlexWaygood, GBeauregard, JelleZijlstra

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-30 Thread Ned Deily


Change by Ned Deily :


--
nosy: +eric.smith

___
Python tracker 

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



[issue47166] Dataclass transform should ignore TypeAlias variables

2022-03-30 Thread Thomas MK


New submission from Thomas MK :

The dataclass transformation ignores attributes that are annotated as ClassVar. 
I think it should also ignore attributes that are annotated as TypeAlias.

Specifically, I have this usecase in mind:


class RunMode(Enum):
release = auto()
debug = auto()

@dataclass
class Run:
Mode: TypeAlias = RunMode
mode: Mode = Mode.release

--
components: Library (Lib)
messages: 416368
nosy: thomkeh
priority: normal
severity: normal
status: open
title: Dataclass transform should ignore TypeAlias variables
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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