New submission from conchylicultor :
WeakKeyDictionary are great to "associate additional data with an object owned
by other parts of an application", as quoted from the doc:
https://docs.python.org/3/library/weakref.html#weakref.WeakKeyDictionary
However, this currently
conchylicultor added the comment:
Yes, I know I can rename the closure, or wrap the annotation in 'quote'.
I just wanted to point this out as it felt confusing to me.
For instance, it feels inconsistent with:
```
def fn(datetime: datetime.Time): # Works as expected
```
Or:
```
@dataclass
conchylicultor added the comment:
Sure, here is a minimal reproductible example demonstrating the issue:
```
import pathlib
class C:
pathlib: pathlib.Path = None
```
Which raises:
```
File "py", line 5, in C
pathlib: pathlib.Path = None
AttributeError: 'NoneType'
conchylicultor added the comment:
The above example is a real world example I have currently have. Basically I
have some dataclass based configuration like:
in losses.py:
```
class LossesParams:
...
```
in dataset.py:
```
class DatasetParams:
...
```
in config.py
conchylicultor added the comment:
> Do you have an actual use case for self-referential annotations?
I'm not sure I understand the question. My use case is the following:
```
from ... import losses
class A:
losses: losses.Losses = losses.Losses()
```
Currently this is failing be ca
conchylicultor added the comment:
Interestingly mypy, pylint correctly resolve the closure.
```
class A:
dataclasses: dataclasses.Field = dataclasses.field()
A.dataclasses.other # mypy error: "Field[Any]" has no attribute "other"
```
So the current workaro
Change by conchylicultor :
--
components: +Library (Lib) -Interpreter Core
___
Python tracker
<https://bugs.python.org/issue43746>
___
___
Python-bugs-list mailin
Change by conchylicultor :
--
components: +Interpreter Core
type: -> behavior
versions: +Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
___
Python tracker
<https://bugs.python.org/issu
New submission from conchylicultor :
I observe some strange closure behavior for typing annotations when the name is
defined
```
x: x = 1 # Works, __annotation__ == {'x': 1}
```
This creates issue, for example:
```
from ... import losses
class A:
# AttributeError: 'Losses' object has
conchylicultor added the comment:
For the API, I think we could add this feature with a single new
`dataclass(kw_only: bool | str)`
```
@dataclasses.dataclass(kw_only=True)
class A:
a: int
b: int
c: int
# A(*, a, b, c)
@dataclasses.dataclass(kw_only='b')
class A:
a: int
b: int
conchylicultor added the comment:
I don't think this should have been closed.
[1] If the user is using sub_parser, the options are not even displayed. For
example in our https://github.com/tensorflow/datasets project:
```
$ tfds build mnist --overwritte
usage: tfds [-h] [--helpfull
Change by conchylicultor :
--
components: +Library (Lib)
type: -> behavior
versions: +Python 3.10
___
Python tracker
<https://bugs.python.org/issu
New submission from conchylicultor :
Currently, because `BinaryIO` is subclass of `IO[bytes]`, the 2 cannot be used
interchangeably.
Example with pytype:
```
def iter_zip(arch_f) -> List[typing.BinaryIO]]:
with open(arch_f, 'rb') as fobj:
z = zipfile.ZipFile(fobj)
return [z.o
conchylicultor added the comment:
Solving this would significantly improve @dataclass inheritance
(https://bugs.python.org/issue39300). Any idea when this will land ?
Currently, it is not possible to add required argument to a child dataclass
(unless hacks like duplicating attributes
New submission from conchylicultor :
The following code fail with zipfile.Path, but works with pathlib.Path:
```
path = path.joinpath().joinpath('other', 'other')
```
Zipfile:
https://github.com/python/cpython/blob/95ad890a7b0341d8d2fde13f824bc24c65a8ece0/Lib/zipfile.py#L2363
```
def
conchylicultor added the comment:
Closing this as I realize that even if this was solved, it would still not
fully resolve the issue. Basically I want to control how __fspath__ and __str__
behave externally (for users), but internal fspath and str should always call
`super
New submission from conchylicultor :
I'm writing a subclass of `pathlib.Path` with custom `__fspath__`.
To prevent bad usages (users should use `os.fspath(path)` instead of
`str(path)` to access the underlying path), I would like to overwrite `str`:
```
class MyPath(pathlib.PosixPath
17 matches
Mail list logo